home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Leser 15 / Amiga Plus Leser CD 15.iso / Tools / Hardware / BlizKick / BlizKick.ASM < prev    next >
Encoding:
Assembly Source File  |  2002-03-13  |  83.5 KB  |  3,950 lines

  1. ; FILE: Source:BlizKick.ASM          REV: 505 --- BlizKick - the ultimate maprom tool
  2. ; History
  3. ;  1      Running OK!
  4. ;  15     Now BlizKick should work with all Blizzard turbos.
  5. ;  19     Now BlizKick should even support KS 1.0... (?)
  6. ;  25     Added LOCALFAST feature.
  7. ;  31     Added QUICKBOOT feature.
  8. ;  33     Added better Printf.
  9. ;  48     Added Better ROM identification code (checksum).
  10. ;  65     Added "real" cache clear routine.
  11. ;  69     Fixed _seek bug.
  12. ;  71     Fixed KS 1.3 SPEEDROM bug.
  13. ;  81     Replaced "execinit" patch with resident tag.
  14. ;  107    Fix for Blizzard 1260! 1230-IV too!!
  15. ;  111    Added original Kickstart restoration.
  16. ;  114    Implemented KS1.x KS restoration.
  17. ;  115    Improved error messages.
  18. ;  116    Improved MAPROM test and CacheClear routine.
  19. ;  125    Added HOGWAITBLIT feature.
  20. ;  129    Added SetPatch (680x0.library) check.
  21. ;  175    Added MODULE feature.
  22. ;  186    Added EXTRESBUF feature.
  23. ;  210    Added External patches and BKMF_ExtResBuf flag, fixed 1.x ROMTag support.
  24. ;  215    Fixed LOCALFAST feature not to force MEMF_LOCAL or MEMF_KICK!
  25. ;  220    Fixed KS 1.x ROMTag support.
  26. ;  225    Added special handling for 1230-IV and 1260. Fixed FORCE.
  27. ;  240    Removed need to be run before SetPatch on 1260 systems.
  28. ;  248    Can be used with Enforcer, CPU FASTROM, VMM etc.
  29. ;  257    Improved 040/060 cache flushing code. BlizKick release 1.6.
  30. ;  266    Fixed bug in 040/060 MMU test code.
  31. ;  276    Added XPK support.
  32. ;  277    Modified to work better with PowerPC... :)
  33. ;  279    Added better (Old)OpenLibrary code. Removed FindName() things.
  34. ;  289    Fixed XPK support.
  35. ;  293    Now will set memory node name if null.
  36. ;  300    Fixed EXTRESBUF.
  37. ;  302    Fixed negative return code bug.
  38. ;  307    Added ROM address validity test.
  39. ;  311    Fixed BLIZZARD 2060 code.
  40. ;  313    Fixed one terrible bug from B2060 code.
  41. ;  328    Fixing EXTRESBUF...
  42. ;  332    Finished! Now it should work with 1260, 2040 and 2060.
  43. ;  338    DOES work on 1260. Fixed one minor bug. SoftSCSI module doesn't work.
  44. ;  340    Added memheader move code to LOCALFAST. -> Speed AllocMem()
  45. ;  343    Fixed reset code!
  46. ;  344    Allowed BlizKick to kick same kickfile and rom chip version.
  47. ;  348    Fixed .testblizppcrunnommu. Added pseudofile (*) feature.
  48. ;  353    Added LastPatches (fix for MEMF_REVERSE svstack, etc.)
  49. ;  361    Fixed svstack trash, disabled SVSTACKTRASH.
  50. ;  377    Added QUIET switch, fixed LastPatches, KS 33.180 works now!
  51. ;  388    Got KS 33.180 finally work 100%.
  52. ;  389    Added handling for BKMODPATH env variable.
  53. ;  399    Improved HOGWAITBLIT.
  54. ;  400    Found out that 2040 and 2060 boards are almost identical.
  55. ;  403    Fixed reset code to *disable* caches.
  56. ;  404    1.11ß1: Trying to get EXTRESBUF into fastmem.
  57. ;  412    Did it. Seems to work 100%.
  58. ;  415    Fixed MAPROM test. Now should detect if MAPROM not set.
  59. ;  416    Disabled SUPERVISOR_NOREVERSE from LastPatches.
  60. ;  421    Added support for (A4000?) CPU Cards.
  61. ;  425    Now KS 1.x are only patched if they're original versions. This should
  62. ;         prevent problems with some patches 1.x ROM images.
  63. ;  426    Fixed bug in ROM image validation test.
  64. ;  427    9th Dec 1997: ARGH! Wrote nice CPUCard support but forgot to enable
  65. ;         it!!! ;-)
  66. ;  429    Added support for Cyberstorm PPC and MKIII. Now should work at least
  67. ;         with CBM CPU Cards, Cyberstorm MKI, MKIII and PPC.
  68. ;  439    Separated A1200 and other model's check routines. Hopefully fixed CS
  69. ;         MKIII/PPC support. Added CS MKII support. Now CPUCARD is only meant to
  70. ;         be used with CS MKI & compatible.
  71. ;  442    Fixed few typos etc.
  72. ;  443    Fixed stupid BUG from CS support... THANKS DUKEN!! =)
  73. ;  444    Had mixed 20x0 and CS MK II product IDs... doh! Thanks shido at #amiga!
  74. ;  445    Fixed some Lock bugs.
  75. ;  446    13th May 1998 Made the source public in hope someone would continue the
  76. ;         development.
  77. ;  450    6th July 1998 Added Blizzard PPC support.
  78. ;  458    8th July 1998 Fixed Blizzard PPC and CS MKII support (I hope).
  79. ;  459    17th July 1998 Fixed stupid bug from CS MKII support.
  80. ;  461    4th October 1998 Finally fixed the blizz ppc bug. hehe.
  81. ;  462    6th October 1998 Fixed support for old KS.
  82. ;  463    9th October 1998 Fixed MK2 bug. Ta ChaoZer.
  83. ;  464    13th October 1998 Another MK2 fix <sigh>. Ta ChaoZer.
  84. ;  467    3rd November 1998 Disabled rom checksum disable in SPEEDROM.
  85. ;  468    24th January 1999 Fixed stupid blizzppc (and probably CSPPC too)
  86. ;         bug, blizzppc/csppc kernel overwrote EXTRES buffer. Now allocates
  87. ;         1mb extra memory. froze 1.18.
  88. ;  469    7th November 1999 Made BlizKick use fastmem hunks again. Finally
  89. ;         made it possible to `FORCE-after-maprom-is-already-active' and remove
  90. ;         maprom for Blizzard PPC.
  91. ;  470    Implemented new straightforward method to solve BKMODPATH variable
  92. ;         in DoPlanting routine.
  93. ;  471    Doesn't Delay(25) if QUIET is specified.
  94. ;  472    Added 040/060 move16 optimized copymem256.
  95. ;  473    Sped up FindResident and resident module reconnect. froze 1.19.
  96. ;  474    7th Jan 2000: Bumped revision strings to 1.20.
  97. ;  475    8th Jan 2000: Fixed major memory loss on extresbuf Deallocate on error
  98. ;         condition. Also that Deallocate() call wasn't called in Forbid state.
  99. ;  476    9th Jan 2000: New feature: you can give *any* loadsegable executable
  100. ;         as module. Resident modules inside will be initialized. Cool. Renders
  101. ;         SCSIDEV43 module obsolete, just give devs:scsi43.device as one module!
  102. ;         You can also give l:fastfilesystem etc! wooow, this is WAY too cool. :)
  103. ;         This required a change in the internal way of handling EXTRES buffer
  104. ;         + some new InternalLoadSeg code.
  105. ;  477    Now uses move.l an,an as nop when possible. FindResident bugged, it
  106. ;         scanned ROM first, then EXTRES buffer. Fixed to be opposite.
  107. ;  478    Added mmu.library support to getmmu and runnommu routine. This is a
  108. ;         "good thing"(TM).
  109. ;  479    14th Jan 2000: LOCALFAST and QUICKBOOT are now finally gone. Arguments
  110. ;         are there, but do nothing. Now the good news: Finally cleaned up the
  111. ;         code, and changed EXTRES buffer attaching to ROM such way it finally
  112. ;         works everytime on blizzppc. Yes! Added new argument SANITY/K/N to
  113. ;         specify sanity added to EXTRES buffer allocation in kbytes. PoolMem
  114. ;         could have fucked BlizKick in several ways, it changes MemHeaders on
  115. ;         the fly... Fixed. froze 1.20.
  116. ;  480    17th Jan 2000: *MAJOR BUG*: move16 could have easily got source
  117. ;         aligned by only 8 causing copy source shifted by 8 bytes -> non
  118. ;         working rom image. *THIS* has caused all these weird crashed with
  119. ;         different EXTRESBUF sizes. Me & my ultrafast copyloop. Duh! :(
  120. ;         Now uses *only* movem copy.
  121. ;  481    Wrote separate LocalFast module so removed ARG_LOCALFAST completely.
  122. ;         exe module support didn't set error code properly when out of EXTRES
  123. ;         buffer memory. Accidently called dos.library/Open for _gettc when
  124. ;         exec.library/Supervisor should have been called. Fun thing is that
  125. ;         this had so side effects. :) froze 1.21.
  126. ;  482    29th Jan: Fixed some nastiness from Blizzard 1230 maprom .testcode,
  127. ;         dunno if this fixes anything, but anyway it was bugged. mmu.library
  128. ;         getmmu was bugged: it always thought machine had 030 compatible MMU,
  129. ;         this didn't cause any problems though, but was wrong. Oops, stupid
  130. ;         bug in MK2 support, blo instead of bhi. Also 20x0 support could have
  131. ;         been affected. froze 1.22beta1.
  132. ;  483    31th Jan: removed CPU Card test code, I think it prevented it from
  133. ;         working, I hope. froze 1.22beta2.
  134. ;  484    3rd Feb: CS MK II works now, but BlizKick didn't recognize if it was
  135. ;         run before. Tweaked check code to run MMU disabled, see _checkactive.
  136. ;         froze 1.22beta3.
  137. ;  485    24th Feb: Disabled memory header name checks, should now work better
  138. ;         if memory node name is fucked. Fixed LocalFast module, it was kindof
  139. ;         broken. froze 1.22beta4.
  140. ;  486    my BK_MOD macro was fucked in previous release. damn! :(
  141. ;         froze 1.22beta5.
  142. ;  487    6th Mar: InstallModule BKMB_SingleMode misbehaved if module was
  143. ;         already installed. fixed. Forgot to remove LOCALFAST commandline
  144. ;         argument when I wrote LocalFast module. fixed. froze 1.22beta7.
  145. ;  488    7th Mar: Removed _regtemp stuff as mmu.library WithoutMMU passes
  146. ;         registers around. Rewrote runnommu, adding transparent translation
  147. ;         disable for 68030/68040/68060 and proper ATC cache flushing for
  148. ;         68030. Now BlizKick checks for activity first MMU enabled then MMU
  149. ;         disabled. Added elfloadseg-patch ioerr bug workaround, now you get
  150. ;         proper error message when module is not found. Added 256k ROM
  151. ;         support for CPU Cards. froze 1.22beta8.
  152. ;  489    27th Mar: oops, the new 030 runnommu accidently did rts instead of
  153. ;         rte. Definetely broke BlizKick on 030 machines. froze 1.22beta10.
  154. ;  490    28th Apr: No longer tries to open mmu.library if run before
  155. ;         SetPatch. froze 1.22beta11.
  156. ;  491    1st Aug: Bugfix: the 040+ cacheclear routine didn't invalidate the
  157. ;         data and inst cache after flush. froze 1.22beta12.
  158. ;  492    4th Aug: Bugfix: Terrible horrible stupid "nggh ngggh!" -level bug
  159. ;         fixed from 020/030 MMU test code, it fucked up VBR completely! Many
  160. ;         thanks go to "John Stunner" who found this and reported it at
  161. ;         ru.amiga 2nd Aug. Also special thanks to Useless who redirected this
  162. ;         message to me 3rd Aug. This bug was very evil as it fucked up ALL
  163. ;         exception vectors in VBR, every time BlizKick was run. So it made
  164. ;         030 systems very unstable... oh my god! ;) froze 1.22beta13.
  165. ;  493    6th Aug: Fixes to DisableCacheS: now invalidate cache on 040/060.
  166. ;         Made disable 060 superscalar dispatch. froze 1.22beta14.
  167. ;  494    7th Aug: Finally found the reason for CS MK II
  168. ;         'Kickstart wasn't kicked using BlizKick!' -error. When _restore check
  169. ;         failed it fell thru to this error message. Now has special error
  170. ;         message 'Kickstart restoring not supported!' for this case. Should
  171. ;         finally work fine on CS MK II. Now will quit quietly (RC = WARN) if
  172. ;         MorphOS is running. froze 1.22beta15.
  173. ;  495    10th Aug: PutResident RTF_AUTOINIT support was a bit broken. Never
  174. ;         really used, so was harmless. 15th Aug: Improved 030 runnommu not to
  175. ;         mess with mmu registers if mmu seems to be disabled already.
  176. ;  496    2nd Sep: froze 1.22.
  177. ;  497    4th Sep: Fixed silly bug from 030 MMU code, wrong stack offset was
  178. ;         used for restoring TC in runnommu (Remco Komduur). froze 1.23.
  179. ;  498    11th Sep: Total rewrote of the 040/060 cache & MMU code. Much cleaner
  180. ;         implementation now. Bugs fixed: runnommu didn't turn off 68060
  181. ;         StoreBuffer, could have caused malfunction with specific buggy CPU
  182. ;         Cards. runnommu didn't disable the 68060 Branch Cache, if 'Branch
  183. ;         Prediction Error' took place the code might have screwed up. The
  184. ;         CSPPC/CSMKIII/BPPC maprom trigger code restored only partial MMU
  185. ;         setup, and without clearning the ATC cache, if the MMU setup wasn't
  186. ;         standard the code probably screwed up. Maprom trigger code turned
  187. ;         off the 68060 StoreLoadBypass feature, now it isn't touched. Now
  188. ;         mmu.library/WithoutMMU() is only used for pre-68040 CPUs. froze
  189. ;         1.24beta1.
  190. ; 499     12th Oct: fixed small bug in SPEEDROM: the RT_END of the last ROMTag
  191. ;         was made to point to $fffffe. Due some funny side effect ($1000000 -
  192. ;         $fffffe) / 2 - 1 = 0) it caused the ROM's ROMTag scanner access
  193. ;         longword at $fffffe, thus accessing non-existent memory. (maybe this
  194. ;         was it Gunther... :-) froze 1.24beta2.
  195. ; 500     3rd Nov 2000: I broke CPUCARD support when I added 256K rom support
  196. ;         in 1.22beta8. Oh my, oh my, now I feel very stupid.:-).
  197. ; 501     6th Nov 2000: Now this one was funny: I had some really weird & crap
  198. ;         problems with TC_EXCEPTCODE with another project. Turned out that
  199. ;         that BlizKick's final Forbid() was the cause for ALL those problems.
  200. ;         Now that I think of it, it makes NO sense to call Forbid() before
  201. ;         final 'rts' in a CLI program, it is only valid in WB programs. This
  202. ;         bugfix probably solves lots of those weird problems there has been
  203. ;         with BlizKick. froze 1.24beta3.
  204. ; 502     24th Jan 2001: Copyright update recompile. froze 1.24beta5.
  205. ; 503     1st Feb 2001: (Hopefully) added EXTRESBUF support for CPUCARDs
  206. ;         (^Berserk^). Now default to BKMODPATH of "DEVS:Modules/" if the
  207. ;         env variable is not found (Lizard). Added IGNPATH option for
  208. ;         completeness. Reworked B20x0 code, hopefully fixed some problems.
  209. ;         Reworked KickSys to use set of subroutines for different cards,
  210. ;         much cleaner now. froze 1.24beta6.
  211. ; 504     24th Oct 2001: Minor code cleanups. Fixed 12th Oct 2001 flashrom
  212. ;         problem (In the new flashrom the blizzard memory node attributes
  213. ;         was added MEMF_LOCAL flag, which prevented BlizKick from locating
  214. ;         the memory node. Generally this is good thing (TM), since this
  215. ;         finally officially documents the feature that blizzppc memory
  216. ;         doesn't go away at reset. However, I was unable to predict this
  217. ;         change, and while I want BlizKick to be 100% bulletproof when
  218. ;         probing for the memory node, this change broke it). froze 1.24beta7.
  219. ; 505     25th Oct 2001: Fixed massive bug in mmu.library logic. Now it
  220. ;         really should work as expected. If maprom was available but failed
  221. ;         to initialize BlizKick crashed horribly. Fixed. I think these bugs
  222. ;         were added in 1.24beta6. Found a very long standing bug from PUP-
  223. ;         cards reboot code: due to some card reset hardware magic, ExecBase
  224. ;         was never trashed like with other cards. This caused all reset
  225. ;         proof applications to stay in memory, which definetely is not what
  226. ;         should happen. Fixed to behave like other cards. Added commandline
  227. ;         option to disable trashing of ExecBase (KEEPEXEC), however its'
  228. ;         use is not recommended and it can cause some weird problems. Fixed
  229. ;         *very* long standing problem with some PowerUP systems where
  230. ;         rebooting the system gave red screen (ie. ROM checksum wrong).
  231. ;         New commandline option NOPUPREBOOT fixes this behaviour on these
  232. ;         systems. froze 1.24beta8.
  233. ;
  234.  
  235. ;DEBUGMODE    EQU    1        ;don't clone code
  236.  
  237. ;
  238. ; I seriously doubt if this source code is useful for anything else.
  239. ; Hairy code everywhere, this one is really a bitch to maintain...
  240. ;
  241.  
  242. ; TODO (err, not never, maybe, huh)
  243. ; o total rewrite in C (btw is still currently in progress ;-)
  244. ; o unused romtag zapper & support for this extra space to FindSpace.
  245. ;   also add this functionality to applypatch
  246. ; o BootControl module. Maybe. Requested by several users.
  247. ; o ROM checksum (restore orig rom if bad ROM checksum)
  248. ; o possibility to get commandline arguments from a file
  249. ;   (can be emulated with `BlizKick ? <cmd_file')
  250. ;
  251.  
  252. USE_STD_INCLUDES    SET    1
  253.     IFNE    USE_STD_INCLUDES
  254.     MACHINE    MC68040
  255.     include    "exec/types.i"
  256.     include    "exec/nodes.i"
  257.     include    "exec/libraries.i"
  258.     include    "exec/memory.i"
  259.     include    "exec/execbase.i"
  260.     include    "exec/resident.i"
  261.     include    "exec/alerts.i"
  262.     include    "exec/semaphores.i"
  263.     include    "dos/dos.i"
  264.     include    "exec/exec_lib.i"
  265.     include    "dos/dos_lib.i"
  266.     include    "graphics/gfxbase.i"
  267.     include    "graphics/graphics_lib.i"
  268. call    MACRO
  269.     jsr    (_LVO\1,a6)
  270.     ENDM
  271.     ELSE
  272.     include    "Devpac:Gen.gs"
  273.     ENDC
  274.     include    "dos/dosextens.i"
  275.     include    "libraries/configvars.i"
  276.     include    "libraries/expansion_lib.i"
  277.     include    "hardware/dmabits.i"
  278.     include    "hardware/custom.i"
  279.  
  280.     include    "libraries/xpk.i"    ; from xpk_dev
  281.  
  282.     include    "blizkickmodule.i"
  283.  
  284.  
  285. ; mmu.library LVOs
  286.     IFND    _LVOGetMMUType
  287. _LVOGetMMUType    EQU    -$36
  288. _LVOWithoutMMU    EQU    -$10E
  289.     ENDC
  290.  
  291.     IFND    MUTYPE_NONE
  292. MUTYPE_NONE     equ     0
  293. MUTYPE_68851    equ     '2'
  294. MUTYPE_68030    equ     '3'
  295. MUTYPE_68040    equ     '4'
  296. MUTYPE_68060    equ     '6'
  297.     ENDC
  298.  
  299. ; PoolMem uses this to indicate small pool MemHeader.
  300. ; We don't want to get EXTRES buffer memory from such mem...
  301.     BITDEF    MEM,POOLMEM,4
  302.  
  303.  
  304. ; 68040 / 68060 CACR bits
  305.     BITDEF    CACR,HalfICache,13        ;060
  306.     BITDEF    CACR,NoAllocateI,14        ;040/060
  307.     BITDEF    CACR,EnableICache,15        ;040/060
  308.     BITDEF    CACR,ClearUserBCache,21        ;060
  309.     BITDEF    CACR,ClearAllBCache,22        ;060
  310.     BITDEF    CACR,EnableBCache,23        ;060
  311.     BITDEF    CACR,HalfDCache,27        ;060
  312.     BITDEF    CACR,DisableCPUSHInv,28        ;060?
  313.     BITDEF    CACR,EnableStoreBuffer,29    ;060
  314.     BITDEF    CACR,NoAllocateD,30        ;040/060
  315.     BITDEF    CACR,EnableDCache,31        ;040/060
  316.  
  317. ; 68040 / 68060 CACR bitmasks
  318. CACRF_CachesOr040    EQU    CACRF_EnableDCache|CACRF_EnableICache
  319. CACRF_CachesAnd040    EQU    CACRF_NoAllocateI|CACRF_NoAllocateD
  320. CACRF_CachesOr060    EQU    CACRF_CachesOr040|CACRF_EnableStoreBuffer|CACRF_EnableBCache
  321. CACRF_CachesAnd060    EQU    CACRF_CachesAnd040|CACRF_DisableCPUSHInv|CACRF_HalfICache|CACRF_HalfDCache
  322.  
  323. ; 68060 PCR bits
  324.     BITDEF    PCR,EnableDebugFeatures,7    ;060
  325.     BITDEF    PCR,StoreLoadBypass,5        ;060
  326.     BITDEF    PCR,DisableFPU,1        ;060
  327.     BITDEF    PCR,EnableSuperScalar,0        ;060
  328.  
  329.  
  330. ARG_KICKFILE    EQU    0
  331. ARG_MODULE    EQU    4
  332. ARG_EXTRESBUF    EQU    8
  333. ARG_SANITY    EQU    12
  334. ARG_FORCE    EQU    16
  335. ARG_SPEEDROM    EQU    20
  336. ARG_HOGWAITBLIT    EQU    24
  337. ARG_CPUCARD    EQU    28
  338. ARG_IGNPATH    EQU    32
  339. ARG_NOPUPREBOOT    EQU    36
  340. ARG_KEEPEXEC    EQU    40
  341. ARG_QUIET    EQU    44
  342.  
  343. BLIZPROD    EQU    $2140
  344. ROMSUMOFFS    EQU    -$18
  345. ROMSIZEOFFS    EQU    -$14
  346. IDOFFS    EQU    -$10
  347. BLIZKICK_ID    EQU    'BlzK'
  348. DEF_SANITY    EQU    32        ;default allocation sanity buffer, 32k
  349.  
  350. HAVE_SPEEDROMCHECKSUM    EQU    0    ;1 = disable rom checksum on SPEEDROM
  351. HAVE_NEW_ENV_METHOD    EQU    1    ;1 = use new BKMODPATH solve routine
  352. HAVE_DEFBKMODPATH    EQU    1    ;1 = if no BKMODPATH var is found use "DEVS:Modules/"
  353. HAVE_CPUCARDPOKING    EQU    0    ;0 = don't unnecaccarily mess with the CPU Card
  354.  
  355.  
  356.     SECTION    CODE,CODE
  357.  
  358. Main    move.l    a0,a2
  359.     move.l    d0,d2
  360.     move.l    (4).w,a6
  361.  
  362.     lea    (.morphosname,pc),a1
  363.     call    Forbid
  364.     call    FindResident
  365.     move.l    d0,d3
  366.     lea    (_enforcer,pc),a1
  367.     call    FindPort
  368.     lea    (_EnforcerFlag,pc),a0
  369.     move.l    d0,(a0)
  370.     ; Figure out if it is ok to try using mmu.library. requrements:
  371.     ; 1. SetPatch is run
  372.     ; 2. mmu.library is in memory
  373.     lea    (.setpatchname,pc),a1
  374.     call    FindSemaphore
  375.     tst.l    d0
  376.     beq.b    .no_setpatch
  377.     lea    (LibList,a6),a0
  378.     lea    (.mmuname,pc),a1
  379.     call    FindName
  380. .no_setpatch
  381.     ; d0 = nonzero if it's ok to use mmu library
  382.     call    Permit
  383.     tst.l    d3
  384.     beq.b    .no_morphos
  385.     ; quit silently if MorphOS...
  386.     moveq    #RETURN_WARN,d0
  387.     rts
  388. .no_morphos
  389.     ; NOTE: must use d0 for this coz else .dont_try craps!
  390.     tst.l    d0
  391.     beq.b    .dont_try
  392.     lea    (.mmuname,pc),a1
  393.     moveq    #41,d0
  394.     bsr    OpenLib
  395. .dont_try    lea    (_mmubase,pc),a0
  396.     move.l    d0,(a0)
  397.  
  398.     lea    (_ExecBase,pc),a0
  399.     move.l    a6,(a0)
  400.     lea    (_AttnFlags,pc),a0
  401.     move.w    (AttnFlags,a6),(a0)
  402.  
  403.     IFGT    0
  404.     btst    #AFB_68040,(_AttnFlags+1,pc)
  405.     bne.b    .has_040
  406.     lea    (copymem256,pc),a0
  407.     move.w    #$6000|(copymem256_000-copymem256-2),(a0)
  408. .has_040
  409.     ENDC
  410.  
  411.     moveq    #RETURN_FAIL,d7
  412.  
  413.     IFD    DEBUGMODE
  414.  
  415.     bsr    CacheClearOS
  416.     bsr    Copy
  417.     move.l    d0,d7            ; save return code
  418.  
  419.     ELSE
  420.  
  421.     move.l    #COPYCODE_SIZEOF,d0
  422.     move.l    #MEMF_PUBLIC,d1
  423.     call    AllocMem
  424.     tst.l    d0
  425.     beq.b    .exit
  426.  
  427.     move.l    d0,-(sp)        ; store the pointer to stack
  428.     move.l    d0,a1
  429.     lea    (Copy,pc),a0
  430.     move.l    #COPYCODE_SIZEOF,d0
  431.     call    CopyMemQuick        ; copy the code to the MEMF_PUBLIC buffer
  432.     bsr    CacheClearOS
  433.     move.l    (sp),a0            ; restore the buffer ptr
  434.     jsr    (a0)            ; call the code in the buffer
  435.     move.l    d0,d7            ; save return code
  436.     move.l    (sp)+,a1
  437.     move.l    #COPYCODE_SIZEOF,d0    ; free the MEMF_PUBLIC buffer
  438.     call    FreeMem
  439.  
  440.     ENDC
  441. .exit
  442.     ; a6 = execbase
  443.     move.l    (_mmubase,pc),d0
  444.     beq.b    .nommulib
  445.     move.l    d0,a1
  446.     call    CloseLibrary
  447. .nommulib    move.l    d7,d0            ; set return code
  448.     rts                ; *poof*
  449.  
  450. .morphosname    dc.b    'MorphOS',0
  451. .setpatchname    dc.b    '« SetPatch »',0
  452. .mmuname    dc.b    'mmu.library',0
  453.  
  454.  
  455.     CNOP    0,4
  456. Copy
  457.     lea    (DosName,pc),a1
  458.     moveq    #33,d0
  459.     bsr    OpenLib
  460.     move.l    d0,d6
  461.     beq    .exit
  462.     move.l    d0,a6
  463.  
  464.     moveq    #0,d4            Set default!!
  465.  
  466.     cmp.w    #37,(LIB_VERSION,a6)
  467.     shs    d5
  468.  
  469.     ; get mmu type
  470.     bsr    getmmu
  471.     lea    (_mmuflag,pc),a0
  472.     move.b    d0,(a0)
  473.  
  474.     lea    (_Array,pc),a3
  475.     tst.b    d5
  476.     bne.b    .ks20
  477.     clr.l    -1(a2,d2.l)
  478.     subq.l    #1,d2
  479.     beq.b    .do            RESTORE!
  480.     move.l    a2,(a3)
  481.     lea    (_13Help,pc),a0
  482.     cmp.b    #'?',(a2)
  483.     bne.b    .do
  484.     subq.l    #1,d2
  485.     beq    .printmsgexit
  486.     bra.b    .do
  487. .ks20    lea    (_Template,pc),a0
  488.     move.l    a0,d1
  489.     move.l    a3,d2
  490.     moveq    #0,d3
  491.     call    ReadArgs
  492.     move.l    d0,d4
  493.     beq    .badargs
  494.  
  495. .do
  496.     lea    (_Quiet,pc),a0
  497.     move.l    (ARG_QUIET,a3),(a0)
  498.  
  499.     tst.l    (ARG_CPUCARD,a3)
  500.     beq.b    .no_cpucard
  501.     bsr    TestCPUCard
  502.     lea    (_CPUCard,pc),a0
  503.     move.b    d0,(a0)
  504.     bne.b    .has_cpucard
  505.     lea    (NoCPUCard,pc),a0
  506.     bra.b    .printmsgexit
  507. .no_cpucard
  508.  
  509.     bsr    TestHardware
  510.     lea    (NoHardware,pc),a0
  511.     lea    (_BlizROM,pc),a1
  512.     move.l    d0,(a1)
  513.     beq.b    .printmsgexit
  514. .has_cpucard
  515.  
  516.     movem.l    d4-d6/a6,-(sp)
  517.     moveq    #RETURN_ERROR,d7
  518.     lea    (Messu,pc),a0
  519.     bsr    _PrintHeaderf
  520.     bsr    _HeadMain
  521.     movem.l    (sp)+,d4-d6/a6
  522.  
  523. .freeargs    tst.b    d5
  524.     beq.b    .closedos
  525.     move.l    d4,d1
  526.     call    FreeArgs
  527. .closedos    move.l    d6,a1
  528.     move.l    (_ExecBase,pc),a6
  529.     call    CloseLibrary
  530. .exit
  531.     move.l    d7,d0
  532.     rts
  533.  
  534. .printmsgexit    bsr    _PrintHeaderf
  535.     bra.b    .freeargs
  536.  
  537. .badargs    bsr.b    _PrintFault        IN: d5=kickflag, d6=dosbase
  538.     bra.b    .closedos
  539.  
  540.  
  541. ;  IN: d5=kickflag, d6=dosbase
  542. ; OUT: Fault printed
  543. _PrintFault    movem.l    d0-d2/a0-a1/a6,-(sp)
  544.     move.l    (_Quiet,pc),d0
  545.     bne.b    .exit
  546.     move.l    d6,a6
  547.     call    IoErr
  548.     tst.b    d5
  549.     beq.b    .oldie
  550.     move.l    d0,d1
  551.     moveq    #0,d2
  552.     call    PrintFault
  553. .exit    movem.l    (sp)+,d0-d2/a0-a1/a6
  554.     rts
  555.  
  556. .oldie    move.l    d0,-(sp)
  557.     beq.b    .noerr
  558.     lea    (_ks13error,pc),a0
  559.     move.l    sp,a1
  560.     bsr    _Printf
  561. .noerr    addq.l    #4,sp
  562.     bra.b    .exit
  563.  
  564.  
  565. ;  IN: A0=FmtString, A1=Array, a2=Buffer
  566. ; OUT: Formatted text
  567. _Sprintf    movem.l    d0-d1/a0-a3/a6,-(sp)
  568.     move.l    a2,a3
  569.     lea    (.putchar,pc),a2
  570.     move.l    (_ExecBase,pc),a6
  571.     call    RawDoFmt
  572.     movem.l    (sp)+,d0-d1/a0-a3/a6
  573.     rts
  574. .putchar    move.b    d0,(a3)+
  575.     rts
  576.  
  577.  
  578. ;  IN: A0=FmtString, A1=Array, d6=dosbase
  579. ; OUT: Printed text, including program info header
  580. _PrintHeaderf    movem.l    d0-d1/a0-a2/a6,-(sp)
  581.     move.l    (_ExecBase,pc),a6
  582.     move.l    #$10000,d0        ; Allocate 64k buffer
  583.     moveq    #MEMF_ANY,d1
  584.     call    AllocMem
  585.     move.l    d0,-(sp)
  586.     beq.b    .nomem
  587.     movem.l    (3*4,sp),a0-a1
  588.     move.l    (sp),a2
  589.     bsr.b    _Sprintf
  590.     pea    (_Copyright,pc)
  591.     pea    (_Version,pc)
  592.     lea    (.header,pc),a0
  593.     move.l    sp,a1
  594.     bsr.b    _Printf
  595.     addq.l    #8,sp
  596. .nomem    move.l    (sp)+,d0
  597.     beq.b    .exit
  598.     move.l    d0,a1
  599.     move.l    #$10000,d0
  600.     call    FreeMem
  601. .exit    movem.l    (sp)+,d0-d1/a0-a2/a6
  602.     rts
  603. .header    dc.b    $9B,'1;32m%s',$9B,'31m %s.',$9B,'0m',10
  604.     dc.b    '%s',0
  605.     CNOP    0,2
  606.  
  607.  
  608.     STRUCTURE pf_data,0
  609.     APTR    pfd_DosBase
  610.     APTR    pfd_Count
  611.     STRUCT    pfd_Buffer,256
  612.     LABEL    pf_data_SIZEOF
  613.  
  614.     CNOP    0,4
  615. ;;_OutputFH    dc.l    0
  616. ;  IN: A0=FmtString, A1=Array (may be 0), d6=dosbase
  617. ; OUT: Printed text
  618. _Printf
  619. Printf    movem.l    a0-a3/a6/d0-d3,-(sp)
  620.     move.l    (_Quiet,pc),d0
  621.     bne.b    .exit
  622.     lea    (-pf_data_SIZEOF,sp),sp
  623.     move.l    sp,a3
  624.     move.l    d6,(a3)+
  625.     clr.l    (a3)+
  626.     lea    (.newchar,pc),a2
  627.     move.l    (_ExecBase,pc),a6
  628.     call    RawDoFmt
  629.     move.l    d6,a6
  630.     IFD    _OutputFH
  631.     move.l    _OutputFH,d1
  632.     ELSE
  633.     call    Output
  634.     move.l    d0,d1
  635.     ENDC
  636.     move.l    a3,d2
  637.     move.l    (-4,a3),d3
  638.     call    Write
  639.     lea    (pf_data_SIZEOF,sp),sp
  640. .exit    movem.l    (sp)+,a0-a3/a6/d0-d3
  641.     rts
  642. .newchar    movem.l    d0-d3/a0-a1/a3/a6,-(sp)
  643.     move.l    a3,d2                for Write()
  644.     move.l    -(a3),d1
  645.     move.b    d0,4(a3,d1.l)
  646.     addq.b    #1,d1
  647.     move.l    d1,(a3)
  648.     bne.b    .dont_print
  649.     move.l    -(a3),a6
  650.     IFD    _OutputFH
  651.     move.l    _OutputFH,d1
  652.     ELSE
  653.     call    Output
  654.     move.l    d0,d1
  655.     ENDC
  656.     move.l    #256,d3
  657.     call    Write
  658. .dont_print    movem.l    (sp)+,d0-d3/a0-a1/a3/a6
  659.     rts
  660.  
  661.  
  662. ;  IN: d6=dosbase, *must* remain if you're going to call internal _xxx functions
  663. ;      a3=paramarray, is zero if null template, scratch
  664. ;      a6=dosbase, scratch
  665. ; OUT: d7=return code
  666. _HeadMain
  667.     bsr    _checkactive
  668.     move.b    d0,d2
  669.     beq.b    .isactive
  670.     lea    (_checkactive,pc),a0
  671.     bsr    runnommu
  672.     move.b    d0,d2            keep this flag for a while
  673. .isactive
  674.  
  675.     tst.l    (a3)            (ARG_KICKFILE,a3)
  676.     bne.b    .norestore
  677.  
  678.     tst.b    d2
  679.     bne.b    .notactive
  680.     lea    (_restore,pc),a0
  681.     bsr    runnommu
  682.     tst.l    d0
  683.     beq.b    .norestore2
  684.  
  685.     ; a4 & d3 are set
  686.     bsr    KickSys
  687. .norestore2
  688.     lea    (NoRestore,pc),a0
  689.     bra    _Printf
  690. .notactive
  691.     lea    (NoRem,pc),a0
  692.     bra    _Printf
  693. .norestore
  694.  
  695.     moveq    #0,d1            !!
  696.     bsr    SetIoErr
  697.  
  698.     tst.l    (ARG_FORCE,a3)
  699.     bne.b    .force1
  700.  
  701.     moveq    #RETURN_WARN,d7
  702.     tst.b    d2
  703.     beq    .exit            Already kicked!
  704.  
  705.     moveq    #RETURN_ERROR,d7
  706.  
  707. .force1    move.l    (a3),a0            (ARG_KICKFILE,a3),a0
  708.     cmp.b    #'*',(a0)
  709.     bne.b    .not_pseudofile
  710.     tst.b    (1,a0)
  711.     bne.b    .not_pseudofile
  712.  
  713.     ; Handle "*" -file:
  714.     tst.b    d2            Test for kicked ROM.
  715.     beq    .exit            Already kicked!
  716.     lea    $01000000+IDOFFS,a4    Will fail if kicked previously!
  717.     move.l    -(a4),d3        a4=$01000000+ROMSIZEOFFS
  718.     move.l    d3,d0
  719.     moveq    #MEMF_PUBLIC,d1
  720.     move.l    (_ExecBase,pc),a6
  721.     call    AllocMem
  722.     tst.l    d0
  723.     beq    .exit
  724.     move.l    a4,a0
  725.     sub.l    d3,a0
  726.     add.w    #-ROMSIZEOFFS,a0
  727.     move.l    d0,a4
  728.     move.l    a4,a1
  729.     move.l    d3,d0
  730.     call    CopyMemQuick
  731.     move.l    d3,d1
  732.     move.l    d3,d4
  733.     bra.b    .cont_pseudo
  734.  
  735. .not_pseudofile
  736.     bsr    XPKLoad
  737.     beq    .exit
  738.     move.l    a1,a4
  739.     move.l    d1,d3
  740.     move.l    d0,d4
  741.  
  742. .cont_pseudo    and.l    #$FFF3FFFF,d1        256K or 512K ROM
  743.     bne    .free
  744.     cmp.l    #$00080000,d3
  745.     bhi    .free
  746.     lea    ROMSUMOFFS(a4,d3.l),a5
  747.     cmp.l    (4,a5),d3        Compare to romsize
  748.     bne    .free
  749.  
  750.     move.l    (a4),d2
  751.     and.l    #$FFF8FFFF,d2
  752.     cmp.l    #$11104EF9,d2
  753.     bne    .free
  754.     move.l    (4,a4),d2        Test for relocated ROM
  755.     add.l    d3,d2
  756.     swap    d2
  757.     cmp.w    #$0100,d2
  758.     bne    .free
  759.  
  760.     move.l    a4,a0            Get original ROM checksum
  761.     move.l    d3,d0
  762.     bsr    ROMReSum
  763.     lea    (_OrigSum,pc),a0
  764.     move.l    d0,(a0)
  765.  
  766.     movem.l    ($C,a4),d0/d1        Fix for old KS
  767.     addq.l    #1,d0
  768.     bne.b    .nofix
  769.     move.l    d1,($C,a4)
  770. .nofix
  771.     tst.l    (ARG_FORCE,a3)
  772.     bne.b    .force2
  773.  
  774.     moveq    #RETURN_WARN,d7
  775.     lea    $01000000,a1
  776.     move.l    a1,a0
  777.     sub.l    (ROMSIZEOFFS,a0),a0
  778.     move.l    ($C,a0),d0        Test for different version.
  779.     cmp.l    ($C,a4),d0
  780.     bne.b    .kick
  781.  
  782.     cmp.l    #BLIZKICK_ID,(8,a5)    Test for kicked file.
  783.     beq.b    .free
  784.  
  785. .kick    moveq    #RETURN_ERROR,d7
  786. .force2
  787.     move.l    (_Quiet,pc),d0
  788.     bne.b    .no_output
  789.     lea    (Messu2,pc),a0
  790.     lea    ($C,a4),a1
  791.     bsr    _Printf
  792.     move.l    d6,a6
  793.     moveq    #25,d1
  794.     call    Delay
  795. .no_output
  796.     bsr.b    GoForIt
  797.  
  798. .free    move.l    (_ExecBase,pc),a6
  799.     move.l    a4,a1
  800.     move.l    d4,d0
  801.     call    FreeMem
  802.  
  803. .exit    tst.l    d7
  804.     bmi.b    .nexitok
  805.     beq.b    .exitok
  806.     bsr    _PrintFault        IN: d5=kickflag, d6=dosbase
  807.     lea    (Already,pc),a0
  808.     cmp.w    #RETURN_WARN,d7
  809.     beq.b    .thiserr
  810.     lea    (CouldNotKick,pc),a0
  811. .thiserr    move.l    a3,a1
  812.     bra    _Printf
  813. .nexitok    neg.l    d7            result IN d7!!
  814. .exitok    rts
  815.  
  816.  
  817.  
  818. GoForIt    ;illegal
  819.  
  820.     neg.l    d7
  821.     move.l    (_ExecBase,pc),a6
  822.  
  823.     move.l    (ARG_EXTRESBUF,a3),d0
  824.     beq.b    .no_extbuf
  825.     move.l    d0,a0
  826.     move.l    (a0),d1
  827.  
  828.     move.l    #DEF_SANITY,d2
  829.     move.l    (ARG_SANITY,a3),d0
  830.     beq.b    .nosanity
  831.     move.l    d0,a0
  832.     move.l    (a0),d2
  833. .nosanity    lsl.l    #8,d2
  834.     lsl.l    #2,d2            *1024
  835.  
  836.     move.l    a4,a0
  837.     move.l    d3,d0
  838.     bsr    ExtResBuf
  839.     bne.b    .got_extbuf
  840.     bsr    _PrintFault        IN: d5=kickflag, d6=dosbase
  841.     bra.b    .fail
  842. .got_extbuf
  843. .no_extbuf
  844.     tst.l    (ARG_HOGWAITBLIT,a3)
  845.     beq.b    .no_agawblit
  846.     move.l    a4,a0
  847.     move.l    d3,d0
  848.     bsr    PutHogWaitBlit
  849. .no_agawblit
  850.     move.l    a4,a0
  851.     move.l    d3,d0
  852.     bsr    DoPlanting
  853.     beq.b    .fail
  854.  
  855.     tst.l    (ARG_SPEEDROM,a3)
  856.     beq.b    .no_patch2
  857.     move.l    a4,a0
  858.     move.l    d3,d0
  859.     bsr    SpeedROM
  860. .no_patch2
  861.  
  862.     move.l    a4,a0
  863.     move.l    d3,d0
  864.     bsr    LastPatches
  865.  
  866.  
  867.     move.l    #BLIZKICK_ID,IDOFFS(a4,d3.l)
  868.     move.l    a4,a0
  869.     move.l    d3,d0
  870.     bsr.b    ROMReSum
  871.     move.l    d0,ROMSUMOFFS(a4,d3.l)
  872.     bsr    CacheClearOS
  873.  
  874.     bsr    KickSys
  875. .fail
  876.  
  877. ;;    bra    FreeExtResBuf
  878.  
  879. ;  IN: a6=execbase
  880. ; OUT: d0/d1/a0/a1 trashed
  881. FreeExtResBuf
  882.     move.l    (_erh_freeaddr,pc),d0
  883.     beq.b    .xit
  884.     move.l    d0,a1
  885.     move.b    (_MemHeaderFlag,pc),d1
  886.     beq.b    .xit
  887.     call    Forbid
  888.     lea    (_memhead,pc),a0
  889.     bsr    FindMemHeader
  890.     beq.b    .cantfind
  891.     move.l    (_erh_alloclen,pc),d0
  892.     call    Deallocate
  893. .cantfind    call    Permit
  894.     lea    (_erh_freeaddr,pc),a0
  895.     clr.l    (a0)
  896. .xit    rts
  897.  
  898.  
  899. ROMReSum    move.l    d0,d1
  900.     lsr.l    #2,d1
  901.     move.l    ROMSUMOFFS(a0,d0.l),d0
  902.     not.l    d0
  903. .loop    add.l    (a0)+,d0
  904.     bcc.b    .skip
  905.     addq.l    #1,d0
  906. .skip    subq.l    #1,d1
  907.     bne.b    .loop
  908.     not.l    d0
  909.     rts
  910.  
  911.  
  912.  
  913.     ; Test for kicked ROM:
  914. _checkactive    cmp.l    #BLIZKICK_ID,$01000000+IDOFFS
  915.     sne    d0
  916.     rts
  917.  
  918.  
  919. _restore    lea    $0B80000,a4        Magic address!
  920.     move.l    (ROMSIZEOFFS,a4),d3
  921.     move.l    d3,d0
  922.     and.l    #$FFF3FFFF,d0        256K or 512K ROM
  923.     bne.b    .exitrts
  924.     cmp.l    #$00080000,d3
  925.     bhi.b    .exitrts
  926.     sub.l    d3,a4
  927.  
  928.     ; sanity check...
  929.     move.l    (a4),d0
  930.     and.l    #$FFF8FFFF,d0
  931.     cmp.l    #$11104EF9,d0
  932.     bne.b    .exitrts
  933.  
  934.     moveq    #1,d0
  935.     rts
  936. .exitrts    moveq    #0,d0
  937.     rts
  938.  
  939.  
  940. ;  IN: -
  941. ; OUT: d0=0 if no mmu, -1 if 040/060 mmu, 1 if 030/851 MMU.
  942. getmmu    movem.l    d1-a6,-(sp)
  943.     moveq    #0,d7
  944.  
  945.     move.l    (_mmubase,pc),d0
  946.     bne.b    .use_mmulib
  947.  
  948.     move.l    (_ExecBase,pc),a6
  949.     move.w    (AttnFlags,a6),d0
  950.     btst    #AFB_68020,d0
  951.     beq.b    .exit
  952.     cmp.w    #37,(LIB_VERSION,a6)
  953.     blo.b    .oldtest
  954.  
  955.     moveq    #-1,d7
  956.     lea    (.test040plus,pc),a5
  957.     btst    #AFB_68040,d0
  958.     bne.b    .test
  959. .oldtest    moveq    #1,d7
  960.     lea    (.test020plus,pc),a5
  961.  
  962. .test    call    Disable
  963.     call    Supervisor
  964.     call    Enable
  965.  
  966. .exit    move.l    d7,d0
  967.     movem.l    (sp)+,d1-a6
  968.     rts
  969.  
  970.  
  971. .use_mmulib    move.l    d0,a6    
  972.     call    GetMMUType
  973.     move.b    d0,d7
  974.     beq.b    .exit
  975.  
  976.     moveq    #-1,d7
  977.     cmp.b    #MUTYPE_68040,d0    040 MMU
  978.     beq.b    .exit
  979.     cmp.b    #MUTYPE_68060,d0    060 MMU
  980.     beq.b    .exit
  981.  
  982.     moveq    #1,d7            851/030 MMU
  983.     bra.b    .exit
  984.  
  985.  
  986. .test040plus    or.w    #$700,sr        Disable interrupts.
  987.     movec    vbr,a0            Get VBR
  988.     move.l    ($10,a0),-(sp)        Save Illegal Instruction vector
  989.     move.l    a0,-(sp)        Save VBR
  990.     lea    (.illegal040,pc),a1
  991.     move.l    a1,($10,a0)
  992.     cpusha    bc
  993.     cinva    bc
  994.  
  995.     movec    tc,d0            $4e7a0003    Test some "common" MMU regs:
  996.     movec    urp,d1            $4e7a1806    Test 040/060 MMU only reg!!
  997.     movec    srp,d1            $4e7a1807    Test 040/060 MMU only reg!!
  998.     nop
  999. .exit040
  1000.     move.l    (sp)+,a0
  1001.     move.l    (sp)+,($10,a0)        Restore Illegal Instruction vector
  1002.     cpusha    bc
  1003.     cinva    bc
  1004.     nop
  1005.     rte
  1006.  
  1007.  
  1008.     CNOP    0,4
  1009. .illegal040    moveq    #0,d7
  1010.     lea    (.exit040,pc),a0
  1011.     move.l    a0,(2,sp)
  1012.     cpusha    bc
  1013.     cinva    bc
  1014.     nop
  1015.     rte
  1016.  
  1017.  
  1018. .test020plus    or.w    #$700,sr        Disable interrupts.
  1019.  
  1020.     ;···
  1021.  
  1022.     movec    vbr,a0            Get VBR
  1023.     move.l    ($10,a0),-(sp)        Save Illegal Instruction vector
  1024.     move.l    ($2C,a0),-(sp)        Save F-Line Emul vector
  1025.     move.l    ($E0,a0),-(sp)        Save MMU Config Error vector
  1026.     move.l    ($E4,a0),-(sp)        Save MMU Illegal Operation Error vector
  1027.     move.l    ($E8,a0),-(sp)        Save MMU Access Level Violation Error vector
  1028.     move.l    a0,-(sp)        Save VBR
  1029.  
  1030.     subq.l    #4,sp            Bug: This was at ··· before ("John Stunner" & Useless)
  1031.  
  1032.     lea    (.mmuinstfailure,pc),a1
  1033.     move.l    a1,($10,a0)
  1034.     move.l    a1,($2C,a0)
  1035.     move.l    a1,($E0,a0)
  1036.     move.l    a1,($E4,a0)
  1037.     move.l    a1,($E8,a0)
  1038.  
  1039.     bsr    _flush020
  1040.  
  1041.     ; Try to get TC
  1042.     dc.w    $F000,$2400        pflusha
  1043.     dc.w    $F017,$4200        pmove.l tc,(sp)
  1044.     dc.w    $F000,$2400        pflusha
  1045. .exitsuper
  1046.     addq.l    #4,sp
  1047.     move.l    (sp)+,a0        Restore VBR
  1048.     move.l    (sp)+,($E8,a0)        Restore MMU Access Level Violation Error vector
  1049.     move.l    (sp)+,($E4,a0)        Restore MMU Illegal Operation vector
  1050.     move.l    (sp)+,($E0,a0)        Restore MMU Config Error vector
  1051.     move.l    (sp)+,($2C,a0)        Restore F-Line Emul vector
  1052.     move.l    (sp)+,($10,a0)        Restore Illegal...
  1053. .exitall    bsr.b    _flush020
  1054.     nop
  1055.     rte
  1056.  
  1057. .mmuinstfailure    moveq    #0,d7
  1058.     lea    (.exitsuper,pc),a0    Invalid mmu instruction!
  1059.     move.l    a0,(2,sp)
  1060.     bsr.b    _flush020
  1061.     nop
  1062.     rte
  1063.  
  1064. _flush020    move.l    d0,-(sp)
  1065.     movec    cacr,d0
  1066.     or.w    #CACRF_ClearI!CACRF_ClearD,d0
  1067.     movec    d0,cacr
  1068.     move.l    (sp)+,d0
  1069.     rts
  1070.  
  1071.  
  1072. ; runnommu -- run routine with mmu disabled
  1073. ;
  1074. ;  IN: a0=code to run in supervisor, mmu off. *MUST* return with rts!!
  1075. ; OUT: d0=whatever values routine leaves to d0. cc's set accordingly.
  1076. ;NOTE: registers d0-d7/a0-a4 are passed to routine as is. Also routine
  1077. ;      can return these registers.
  1078. ;
  1079. runnommu    movem.l    a5/a6,-(sp)
  1080.     move.l    (_mmubase,pc),-(sp)
  1081.     bne    .use_mmulib
  1082. .dont_use    move.l    (_ExecBase,pc),a6
  1083.     move.b    (_mmuflag,pc),(sp)
  1084.     lea    (.discodenommu,pc),a5
  1085.     addq.l    #4,sp
  1086.     beq.b    .doit
  1087.     lea    (.discode020,pc),a5
  1088.     bpl.b    .doit
  1089.     lea    (.discode040,pc),a5
  1090. .doit    call    Disable
  1091.     call    Supervisor
  1092.     call    Enable
  1093. .exit    movem.l    (sp)+,a5/a6
  1094.     tst.l    d0
  1095.     rts
  1096.  
  1097. .use_mmulib    ; only use mmu.library WithoutMMU() for 68020/68030
  1098.     btst    #AFB_68040,(_AttnFlags+1,pc)
  1099.     bne.b    .dont_use
  1100.  
  1101.     move.l    (sp)+,a6
  1102.     move.l    a0,a5
  1103.     call    WithoutMMU
  1104.     bsr    CacheClearOS
  1105.     bra.b    .exit
  1106.  
  1107.  
  1108. .discodenommu    or.w    #$700,sr
  1109.     jsr    (a0)
  1110.     bsr    CacheClrS
  1111.     nop
  1112.     rte
  1113.  
  1114. .discode020    or.w    #$700,sr
  1115.     subq.l    #4,sp
  1116.     dc.w    $F017,$4200        pmove.l tc,(sp)
  1117.     subq.l    #4,sp
  1118.     dc.w    $F017,$0E00        pmove.l tt1,(sp)
  1119.     subq.l    #4,sp
  1120.     dc.w    $F017,$0A00        pmove.l tt0,(sp)
  1121.     clr.l    -(sp)
  1122.     dc.w    $F000,$2400        pflusha
  1123.     tst.w    (1*4+2,sp)
  1124.     bpl.b    .dontdis1
  1125.     dc.w    $F017,$0800        pmove.l (sp),tt0
  1126. .dontdis1    tst.w    (2*4+2,sp)
  1127.     bpl.b    .dontdis2
  1128.     dc.w    $F017,$0C00        pmove.l (sp),tt1
  1129. .dontdis2    tst.l    (3*4,sp)
  1130.     bpl.b    .dontdis3
  1131.     dc.w    $F000,$2400        pflusha
  1132.     dc.w    $F017,$4000        pmove.l    (sp),tc
  1133. .dontdis3    dc.w    $F000,$2400        pflusha
  1134.     addq.l    #4,sp
  1135.     bsr    _flush020
  1136.     jsr    (a0)
  1137.     bsr    _flush020
  1138.     dc.w    $F000,$2400        pflusha
  1139.     tst.w    (2,sp)
  1140.     bpl.b    .dontrest1
  1141.     dc.w    $F017,$0800        pmove.l (sp),tt0
  1142. .dontrest1    addq.l    #4,sp
  1143.     tst.w    (2,sp)
  1144.     bpl.b    .dontrest2
  1145.     dc.w    $F017,$0C00        pmove.l (sp),tt1
  1146. .dontrest2    addq.l    #4,sp
  1147.     tst.l    (sp)            NOTE: can't use (sp)+ !
  1148.     bpl.b    .dontrest3
  1149.     dc.w    $F000,$2400        pflusha
  1150.     dc.w    $F017,$4000        pmove.l    (sp),tc
  1151. .dontrest3    addq.l    #4,sp
  1152.     dc.w    $F000,$2400        pflusha
  1153.     bsr    _flush020
  1154.     nop
  1155.     rte
  1156.  
  1157.  
  1158. .discode040    or.w    #$700,sr
  1159.     movem.l    d0/a0,-(sp)
  1160.     lea    (_mmuregs,pc),a0
  1161.     movec    itt0,d0
  1162.     move.l    d0,(a0)+
  1163.     movec    itt1,d0
  1164.     move.l    d0,(a0)+
  1165.     movec    dtt0,d0
  1166.     move.l    d0,(a0)+
  1167.     movec    dtt1,d0
  1168.     move.l    d0,(a0)+
  1169.     movec    cacr,d0
  1170.     move.l    d0,(a0)+
  1171.     movec    tc,d0
  1172.     move.l    d0,(a0)+
  1173.     cpusha    bc            make sure the above are stored
  1174.     cinva    bc
  1175.     ; LAmask=$ff E=%1 S=%10 (Ignore FC2 when matching), CM=%00 (Cacheable, Writethrough), W=%0 (R/W)
  1176.     move.l    #$00FFC000,d0
  1177.     movec    d0,itt0
  1178.     movec    d0,itt1
  1179.     movec    d0,dtt1
  1180.     ; LAmask=$00 E=%1 S=%10 (Ignore FC2 when matching) CM=%10 (Cache-Inhibited, Precise Exception Model), W=%0 (R/W)
  1181.     move.l    #$0000C040,d0
  1182.     movec    d0,dtt0
  1183.     ; NAD = 0, ESB = 0, DPI = 0, FOC = 0, EBC = 0, NAI = 0, FIC = 0
  1184.     ; EDC = 1, EIC = 1
  1185.     move.l    #CACRF_EnableDCache|CACRF_EnableICache,d0
  1186.     movec    d0,cacr
  1187.     ; E = 0, P = 0, NAD = 0, NAI = 0, FOTC = 0, FITC = 0, DCO = 00
  1188.     ; DUO = 00, DWO = 0, DCI = 00, DUI = 00,
  1189.     moveq    #0,d0
  1190.     pflusha
  1191.     movec    d0,tc
  1192.     movem.l    (sp)+,d0/a0
  1193.     jsr    (a0)
  1194.     cpusha    bc
  1195.     cinva    bc
  1196.     movem.l    d0/a0,-(sp)
  1197.     lea    (_mmuregs,pc),a0
  1198.     move.l    (a0)+,d0
  1199.     movec    d0,itt0
  1200.     move.l    (a0)+,d0
  1201.     movec    d0,itt1
  1202.     move.l    (a0)+,d0
  1203.     movec    d0,dtt0
  1204.     move.l    (a0)+,d0
  1205.     movec    d0,dtt1
  1206.     move.l    (a0)+,d0
  1207.     movec    d0,cacr
  1208.     move.l    (a0)+,d0
  1209.     pflusha
  1210.     movec    d0,tc
  1211.     cpusha    bc
  1212.     cinva    bc
  1213.     movem.l    (sp)+,d0/a0
  1214.     nop
  1215.     rte
  1216.  
  1217.  
  1218. ; runwithmmu040 -- run routine with original mmu setup, 040/060
  1219. ;
  1220. ;  IN: a0=code to run with origiginal mmu state. *MUST* return with rts!!
  1221. ; OUT: d0=whatever values routine leaves to d0. cc's set accordingly.
  1222. ;NOTE: registers d0-d7/a0-a6 are passed to routine as is. Also routine
  1223. ;      can return these registers.
  1224. ;
  1225. ; WARNING! ONLY CALL THIS ROUTINE WITHIN runnommu code!
  1226. ;
  1227. runwithmmu040    move.l    d0,-(sp)
  1228.     move.b    (_mmuflag,pc),d0
  1229.     bmi.b    .got
  1230.  
  1231.     move.l    (sp)+,d0
  1232.     bsr    CacheClrS
  1233.     jsr    (a0)
  1234.     bra    CacheClrS
  1235. .got
  1236.     movec    tc,d0
  1237.     move.l    d0,-(sp)
  1238.     movec    cacr,d0
  1239.     move.l    d0,-(sp)
  1240.     movec    dtt1,d0
  1241.     move.l    d0,-(sp)
  1242.     movec    dtt0,d0
  1243.     move.l    d0,-(sp)
  1244.     movec    itt1,d0
  1245.     move.l    d0,-(sp)
  1246.     movec    itt0,d0
  1247.     move.l    d0,-(sp)
  1248.     cpusha    bc            make sure the above are stored
  1249.     cinva    bc
  1250.     move.l    (_itt0,pc),d0
  1251.     movec    d0,itt0
  1252.     move.l    (_itt1,pc),d0
  1253.     movec    d0,itt1
  1254.     move.l    (_dtt0,pc),d0
  1255.     movec    d0,dtt0
  1256.     move.l    (_dtt1,pc),d0
  1257.     movec    d0,dtt1
  1258.     move.l    (_cacr,pc),d0
  1259.     movec    d0,cacr
  1260.     move.l    (_tc,pc),d0
  1261.     pflusha
  1262.     movec    d0,tc
  1263.     cpusha    bc
  1264.     cinva    bc
  1265.     move.l    (6*4,sp),d0
  1266.     jsr    (a0)
  1267.     cpusha    bc
  1268.     cinva    bc
  1269.     move.l    d0,(6*4,sp)
  1270.     move.l    (sp)+,d0
  1271.     movec    d0,itt0
  1272.     move.l    (sp)+,d0
  1273.     movec    d0,itt1
  1274.     move.l    (sp)+,d0
  1275.     movec    d0,dtt0
  1276.     move.l    (sp)+,d0
  1277.     movec    d0,dtt1
  1278.     move.l    (sp)+,d0
  1279.     movec    d0,cacr
  1280.     move.l    (sp)+,d0
  1281.     pflusha
  1282.     movec    d0,tc
  1283.     cpusha    bc
  1284.     cinva    bc
  1285.     move.l    (sp)+,d0
  1286.     rts
  1287.  
  1288.  
  1289. ;  IN: a5 = memheader
  1290. ;      a6 = execbase
  1291. FoundMem    move.l    a5,a0            for Allocate_REVERSE
  1292.     lea    (_memhead,pc),a1
  1293.     moveq    #MH_FIRST,d0
  1294.     call    CopyMem
  1295.     lea    (_MemHeaderFlag,pc),a0
  1296.     st    (a0)
  1297.     rts
  1298.  
  1299.  
  1300.  
  1301. ; TestHardware - test & query remap hardware
  1302. TestHardware    movem.l    d1-a6,-(sp)
  1303.     moveq    #0,d7            default: no supported hardware found
  1304.     move.l    (_ExecBase,pc),a6
  1305.  
  1306.     bsr    .testblizzppc
  1307.     bne    .exit_np
  1308.  
  1309.     lea    (.ExpName,pc),a1
  1310.     moveq    #33,d0
  1311.     bsr    OpenLib
  1312.     beq    .exit_np
  1313.     move.l    d0,a6
  1314.  
  1315.     lea    (.boards,pc),a2
  1316.     moveq    #0,d2
  1317.     moveq    #0,d6            clear maprom address lower...
  1318. .bfloop    moveq    #0,d0
  1319.     moveq    #0,d1
  1320.     move.w    (a2)+,d0        manufacturer
  1321.     bmi.b    .bfnomatch
  1322.     move.w    (a2)+,d1        product
  1323.     move.w    (a2)+,d6        maprom address, upper word
  1324.     move.l    (a2)+,d3        lower <<16 | upper ram area or -1
  1325.     sub.l    a0,a0
  1326.     call    FindConfigDev
  1327.     move.l    d0,d2
  1328.     beq.b    .bfloop
  1329. .bfnomatch    move.l    a6,a1
  1330.     move.l    (_ExecBase,pc),a6
  1331.     call    CloseLibrary
  1332.     tst.l    d2
  1333.     beq.b    .exit_np
  1334.     swap    d6            maprom address in d6
  1335.     move.l    d2,a0
  1336.     moveq    #0,d0
  1337.     move.b    (cd_Rom+er_Product,a0),d0
  1338.  
  1339.     lea    (_MK2,pc),a0
  1340.     cmp.w    #$19,d0
  1341.     seq    (a0)
  1342.     lea    (_B20x0,pc),a0
  1343.     cmp.w    #$18,d0
  1344.     seq    (a0)
  1345.     lea    (_CSPPC_MK3,pc),a0
  1346.     cmp.w    #$64,d0
  1347.     seq    (a0)
  1348.  
  1349.     move.l    d3,d0            lower & upper ram area for .csfindmemscan
  1350.     lea    (.blizfindmem,pc),a0
  1351.     addq.l    #1,d0
  1352.     beq.b    .skip            -1 it's blizzard!
  1353.     lea    (.csfindmem,pc),a0
  1354. .skip    call    Forbid
  1355.     lea    (MemList,a6),a5
  1356.     lea    (LH_TAIL,a5),a4
  1357.     jmp    (a0)
  1358.  
  1359. .exitsp
  1360.     move.l    d7,d0
  1361. .exit_known    call    Permit
  1362. .exit_np    tst.l    d0
  1363.     bne.b    .foundvalid
  1364.     lea    (_MemHeaderFlag,pc),a0
  1365.     clr.b    (a0)
  1366. .foundvalid    movem.l    (sp)+,d1-a6
  1367.     rts
  1368.  
  1369.  
  1370.  
  1371. ;  IN: a6 = execbase
  1372. ; OUT: d0 = status
  1373. .testblizzppc    btst    #AFB_68040,(_AttnFlags+1,pc)    ; blizzppc card has at least 040 CPU
  1374.     beq    .pexit2
  1375.  
  1376.     lea    (.pidtag,pc),a1            ; try to find the resident romtag
  1377.     call    FindResident
  1378.     tst.l    d0                ; if we found it, be happy
  1379.     bne.b    .foundit
  1380.  
  1381.     lea    (.nastyfind,pc),a0        ; if not, try find it the hw banging
  1382.     bsr    runnommu            ; way...
  1383.     beq    .pexit2
  1384.  
  1385. .foundit    call    Forbid
  1386.  
  1387.     lea    (MemList,a6),a5            ; find the blizzppc memory node
  1388.     lea    (LH_TAIL,a5),a4
  1389. .pscanloop    move.l    (a5),a5
  1390.     cmp.l    a5,a4
  1391.     beq    .pexit
  1392. ;;flashfix    move.w    #MEMF_POOLMEM!MEMF_PUBLIC!MEMF_CHIP!MEMF_FAST!MEMF_LOCAL!MEMF_24BITDMA,d0
  1393.     move.w    #MEMF_POOLMEM!MEMF_PUBLIC!MEMF_CHIP!MEMF_FAST!MEMF_24BITDMA,d0
  1394.     and.w    (MH_ATTRIBUTES,a5),d0
  1395.     cmp.w    #MEMF_FAST!MEMF_PUBLIC,d0
  1396.     bne.b    .pscanloop
  1397. ;;    tst.l    (LN_NAME,a5)
  1398. ;;    bne.b    .pscanloop
  1399.     cmp.l    #$40000000,(MH_LOWER,a5)
  1400.     blo.b    .pscanloop
  1401.     move.l    (MH_UPPER,a5),d0
  1402.     cmp.l    #$80000000,d0
  1403.     bhs.b    .pscanloop
  1404.     and.l    #$0007FFFF,d0
  1405.     beq.b    .pfoundit
  1406.  
  1407. .pexit    call    Permit
  1408. .pexit2    moveq    #0,d0
  1409.     rts
  1410.  
  1411. .pfoundit    bsr    FoundMem
  1412.  
  1413.     call    Permit
  1414.  
  1415.     lea    (_BlizPPC,pc),a0
  1416.     st    (a0)
  1417.  
  1418.     move.l    #$FFF00000,d0
  1419.     rts
  1420.  
  1421.  
  1422. .nastyfind    lea    $F00020,a0        BlizzPPC flash is located here...
  1423.     move.l    #4000,d0        Must use .l!
  1424.     movem.l    (.pidtag,pc),d1-d4
  1425.  
  1426. .nf_find    cmp.l    (a0),d1
  1427.     bne.b    .nf_more
  1428.     cmp.l    (4,a0),d2
  1429.     bne.b    .nf_more
  1430.     cmp.l    (8,a0),d3
  1431.     bne.b    .nf_more
  1432.     cmp.l    (12,a0),d4
  1433.     bne.b    .nf_more
  1434.  
  1435.     moveq    #1,d0
  1436.     rts
  1437.  
  1438. .nf_more    addq.l    #1,a0
  1439.     subq.l    #1,d0
  1440.     bne.b    .nf_find
  1441.     rts
  1442.  
  1443. .pidtag    dc.b    'BlizzardPPC.IDTag',0
  1444.     CNOP    0,2
  1445.  
  1446.  
  1447.  
  1448. .blizfindmem
  1449. .trymore    sub.l    a3,a3
  1450. .scanloop    move.l    (a5),a5
  1451.     cmp.l    a5,a4
  1452.     beq    .exitsp
  1453.     moveq    #MEMF_POOLMEM!MEMF_CHIP!MEMF_FAST!MEMF_PUBLIC,d0    Public fast?
  1454.     and.w    (MH_ATTRIBUTES,a5),d0
  1455.     cmp.w    #MEMF_FAST!MEMF_PUBLIC,d0
  1456.     bne.b    .scanloop
  1457.     cmp.l    #$01000000,(MH_LOWER,a5)    32bit?
  1458.     blo.b    .scanloop
  1459. ;;    move.l    (LN_NAME,a5),d0
  1460. ;;    beq.b    .found
  1461. ;;    move.l    d0,a2
  1462. ;;    move.l    (a2),d0
  1463. ;;    or.l    #$20202020,d0        To lowercase
  1464. ;;    cmp.l    #'bliz',d0
  1465. ;;    beq.b    .found
  1466. ;;    tst.b    (a2)            null name -> buggy AllocMem result test!
  1467. ;;    bne.b    .scanloop
  1468. ;;.found
  1469.     bsr    FoundMem
  1470.  
  1471.     move.l    (MH_UPPER,a5),a3
  1472.  
  1473.     move.l    a3,d0            Test for MapROM:
  1474.     beq.b    .exit
  1475.     and.l    #$0007FFFF,d0
  1476.     bne.b    .exit
  1477.     move.l    a3,d0
  1478.     and.l    #$00080000,d0
  1479.     beq.b    .exit
  1480.  
  1481.     move.l    d6,d0            "known"?
  1482.     bne    .exit_known
  1483.  
  1484.     move.l    a3,a2
  1485.     add.l    #$80000-4,a2
  1486.     lea    $00F80000+$80000-4,a1
  1487.  
  1488.     lea    (.testcode,pc),a0
  1489.     bsr    runnommu
  1490.     beq.b    .exit
  1491.     move.l    a3,d7
  1492. .exit    tst.l    d7
  1493.     beq    .trymore
  1494.     bra    .exitsp
  1495.  
  1496.  
  1497. .is_mk2    move.l    #$08000000,d1
  1498.     move.l    #$10000000,d2
  1499. .mk2scanloop    move.l    (a5),a5
  1500.     cmp.l    a5,a4
  1501.     beq    .exitsp
  1502.     moveq    #MEMF_POOLMEM!MEMF_CHIP!MEMF_FAST!MEMF_PUBLIC,d0    Public fast?
  1503.     and.w    (MH_ATTRIBUTES,a5),d0
  1504.     cmp.w    #MEMF_FAST!MEMF_PUBLIC,d0
  1505.     bne.b    .mk2scanloop
  1506.     cmp.l    (MH_LOWER,a5),d1
  1507.     bhi.b    .mk2scanloop        bug: was blo!
  1508.     cmp.l    (MH_UPPER,a5),d2
  1509.     blo.b    .mk2scanloop
  1510.  
  1511.     bsr    FoundMem
  1512.  
  1513.     move.l    (MH_UPPER,a5),d0
  1514.     move.l    #$80000,d1
  1515.     move.l    d0,d2
  1516.     and.l    d1,d2
  1517.     bne.b    .mk2skip
  1518.     sub.l    d1,d0
  1519. .mk2skip    move.l    d0,d7
  1520.     bra    .exitsp
  1521.  
  1522.  
  1523.  
  1524. .csfindmem    move.b    (_MK2,pc),d0
  1525.     bne.b    .is_mk2
  1526.  
  1527. .cstrymore    sub.l    a3,a3
  1528. .csscanloop    move.l    (a5),a5
  1529.     cmp.l    a5,a4
  1530.     beq    .exitsp
  1531.     moveq    #MEMF_POOLMEM!MEMF_CHIP!MEMF_FAST!MEMF_PUBLIC,d0    Public fast?
  1532.     and.w    (MH_ATTRIBUTES,a5),d0
  1533.     cmp.w    #MEMF_FAST!MEMF_PUBLIC,d0
  1534.     bne.b    .csscanloop
  1535.     swap    d3            ; get lower limit
  1536.     cmp.w    (MH_LOWER,a5),d3
  1537.     bhi.b    .csscanloop
  1538.     swap    d3            ; get upper limit
  1539.     cmp.w    (MH_UPPER,a5),d3
  1540.     blo.b    .csscanloop
  1541.  
  1542.     bsr    FoundMem
  1543.  
  1544.     move.l    (MH_UPPER,a5),a3
  1545.  
  1546.     move.l    a3,d0            Test for MapROM:
  1547.     beq.b    .csexit
  1548.     and.l    #$0007FFFF,d0
  1549.     bne.b    .csexit
  1550.  
  1551.     move.l    d6,d0            "known"?
  1552.     bne    .exit_known
  1553.  
  1554.     move.b    (_B20x0,pc),d0
  1555.     beq.b    .no20x0a
  1556.     cmp.w    #$0800,(MH_LOWER,a5)    Test for $08000000 mem.
  1557.     bne.b    .csexit
  1558. .no20x0a
  1559.     move.l    a3,d7
  1560.  
  1561. .csexit    tst.l    d7
  1562.     beq    .cstrymore
  1563.     bra    .exitsp
  1564.  
  1565.  
  1566. ; a1=ROM, a2=RAM
  1567. .testcode    or.w    #$700,sr        Disable interrupts
  1568.  
  1569.     move.l    (a2),d1
  1570.     cmp.l    (a1),d1
  1571.     bne.b    .exite
  1572.     not.l    d1
  1573.     move.l    d1,(a2)
  1574.     bsr    CacheClrS
  1575.     cmp.l    (a1),d1
  1576.     sne    d0
  1577.     not.l    d1            Restore before testing!
  1578.     move.l    d1,(a2)            (this was bugged)
  1579.     bsr    CacheClrS
  1580.     tst.b    d0
  1581.     bne.b    .exite
  1582.     cmp.l    (a1),d1
  1583.     bne.b    .exite
  1584.     moveq    #1,d0
  1585.     rts
  1586. .exite    moveq    #0,d0
  1587.     rts
  1588.  
  1589.  
  1590.  
  1591.  
  1592.  
  1593. BITEM    MACRO
  1594.     dc.w    \2,\3,\1
  1595.     dc.l    \4
  1596.     ENDM
  1597.  
  1598. .boards    BITEM $0000,BLIZPROD,$18,$08001000    18 2040-ERC/2060
  1599.     ;BITEM $0000,BLIZPROD,$0C,$08002000    0C Cyberstorm MKI
  1600.     BITEM $0000,BLIZPROD,$19,0        19 Cyberstorm MKII
  1601.     BITEM $FFF0,BLIZPROD,$64,$08002000    64 Cyberstorm MKIII / PPC
  1602.     BITEM $4FF8,BLIZPROD,$11,-1        11 1230-IV / 1260 / 1240-T/ERC
  1603.     BITEM $1EF8,BLIZPROD,$0D,-1        0D 1230-III
  1604.     BITEM $0FF8,BLIZPROD,$0B,-1        0B 1230-II
  1605. ;;    BITEM $????,BLIZPROD,$??,-1        0? 1230-I
  1606.     dc.w    -1
  1607.  
  1608.  
  1609. .ExpName    dc.b    'expansion.library',0
  1610.     CNOP    0,2
  1611.  
  1612.  
  1613.  
  1614. ; FindMemHeader - find memheader even if it has moved by PoolMem
  1615. ; MUST call this in Forbid()! Use returned memheader before Permit()!
  1616. ;
  1617. ;  IN: a0=clone of MH (up to MH_FIRST) to find
  1618. ;      a6=execbase
  1619. ; OUT: a0=memheader or NULL, Z flag set
  1620. ;
  1621. FindMemHeader    movem.l    d0-d3/a1,-(sp)
  1622.     moveq    #0,d0
  1623.  
  1624.     move.w    (MH_ATTRIBUTES,a0),d1
  1625.     move.w    (LN_TYPE,a0),d2
  1626.     move.l    (LN_NAME,a0),d3
  1627.  
  1628.     lea    (MemList,a6),a0
  1629.     lea    (LH_TAIL,a0),a1
  1630. .find    move.l    (a0),a0
  1631.     cmp.l    a0,a1
  1632.     beq.b    .fail
  1633.     cmp.w    (MH_ATTRIBUTES,a0),d1
  1634.     bne.b    .find
  1635.     cmp.w    (LN_TYPE,a0),d2        type & pri
  1636.     bne.b    .find
  1637.     cmp.l    (LN_NAME,a0),d3
  1638.     bne.b    .find
  1639.  
  1640. .exit    move.l    a0,d0
  1641.     movem.l    (sp)+,d0-d3/a1
  1642.     rts
  1643.  
  1644. .fail    sub.l    a0,a0
  1645.     bra.b    .exit
  1646.  
  1647.  
  1648.  
  1649. ;  IN: a0=rom, d0=rom len
  1650. ; OUT: d0=success, fail if no AGA or WaitBlit func couln't be found
  1651. PutHogWaitBlit    movem.l    d1-a6,-(sp)
  1652.     moveq    #0,d7
  1653.  
  1654.     cmp.w    #39,($C,a0)        Requires rom 39+
  1655.     blo.b    .exit
  1656.  
  1657.     lea    -4(a0,d0.l),a1
  1658.  
  1659.     move.w    $DFF004,d0        Test AGA:
  1660.     and.w    #$7F00,d0
  1661.     lsr.w    #8,d0
  1662.     bclr    #4,d0
  1663.     cmp.b    #$22,d0
  1664.     beq.b    .aga
  1665.     cmp.b    #$23,d0
  1666.     bne.b    .exit
  1667. .aga
  1668.     move.l    #$08390006,d0
  1669. .find    addq.l    #2,a0
  1670.     cmp.l    a1,a0
  1671.     beq.b    .exit
  1672.     cmp.l    (a0),d0
  1673.     bne.b    .find
  1674.     cmp.l    #$00DFF002,(4,a0)
  1675.     bne.b    .find
  1676.     cmp.l    #$66024E75,(8,a0)
  1677.     bne.b    .find
  1678.  
  1679.     cmp.l    #$08390006,(-8,a0)    No KS 1.x!
  1680.     beq.b    .exit
  1681.     cmp.l    #$4A3900DF,(-6,a0)    KS 2.x/3.x:
  1682.     bne.b    .exit
  1683.     subq.l    #6,a0
  1684.     lea    (.waitblit,pc),a1
  1685.     moveq    #(.waitblitend-.waitblit)/2,d0
  1686. .copy    move.w    (a1)+,(a0)+
  1687.     subq.l    #1,d0
  1688.     bne.b    .copy
  1689.     moveq    #1,d7
  1690.  
  1691. .exit    move.l    d7,d0
  1692.     movem.l    (sp)+,d1-a6
  1693.     rts
  1694.  
  1695.     ; 1.x  36 bytes
  1696.     ; 2.05 40 bytes
  1697.     ; 3.0  48 bytes
  1698.     ; 3.1  48 bytes
  1699. .waitblit    btst    #DMAB_BLTDONE-8,$DFF000+dmaconr            8
  1700.     bne.b    .gowait                        2
  1701.     rts                            2
  1702. .gowait    move.l    a0,-(sp)                    2
  1703.     lea    ($DFF000+dmaconr),a0                6
  1704.     move.w    #DMAF_SETCLR!DMAF_BLITHOG,(dmacon-dmaconr,a0)    6
  1705. .wait    btst    #DMAB_BLTDONE-8,(a0)                4
  1706.     bne.b    .wait                        2
  1707.     move.w    #DMAF_BLITHOG,(dmacon-dmaconr,a0)        6
  1708.     move.l    (sp)+,a0                    2
  1709.     rts                            2 =42
  1710.     IFGT    0
  1711. .gowait    move.w    #DMAF_SETCLR!DMAF_BLITHOG,$DFF000+dmacon    8
  1712. .wait    btst    #DMAB_BLTDONE-8,$DFF000+dmaconr    8
  1713.     bne.b    .wait                2
  1714.     move.w    #DMAF_BLITHOG,$DFF000+dmacon    8
  1715.     rts                    2 =40
  1716.     ENDC
  1717. .waitblitend
  1718.     IFGT    (.waitblitend-.waitblit)-42
  1719.     FAIL    !! WAITBLIT routine too long !!
  1720.     ENDC
  1721.  
  1722.  
  1723.  
  1724. ;  IN: a0=rom start (buf)
  1725. ;      d0=rom len
  1726. ;      a1=name
  1727. ; OUT: d0=ptr to resident (buf) or NULL
  1728. FindResident    movem.l    d1-a6,-(sp)
  1729.     move.l    a1,a3
  1730.  
  1731.     move.l    d0,d4
  1732.     move.l    a0,a4
  1733.  
  1734.     moveq    #1,d6
  1735.     lea    (_erh_arealen,pc),a0
  1736.     move.l    (a0)+,d0
  1737.     beq.b    .try_rom
  1738.  
  1739.     move.l    (a0),a0
  1740.     sub.l    a5,a5            Difference=0
  1741.  
  1742. .findres    moveq    #RT_SIZE-2,d1
  1743.     sub.l    d1,d0
  1744.     move.w    #RTC_MATCHWORD,d1
  1745. .find    subq.l    #2,d0
  1746.     bls.b    .try_rom
  1747.     cmp.w    (a0)+,d1
  1748.     bne.b    .find
  1749.     moveq    #2,d2
  1750.     add.l    (a0),d2            (RT_MATCHTAG-2,a0),d2
  1751.     add.l    a5,d2
  1752.     cmp.l    a0,d2
  1753.     bne.b    .find
  1754.     move.l    (RT_NAME-2,a0),a1
  1755.     add.l    a5,a1
  1756.     move.l    a3,a2
  1757. .compare    cmpm.b    (a2)+,(a1)+
  1758.     bne.b    .find
  1759.     tst.b    (-1,a2)
  1760.     bne.b    .compare
  1761.  
  1762.     move.l    a0,d0
  1763.     subq.l    #2,d0
  1764.  
  1765. .exit    movem.l    (sp)+,d1-a6
  1766.     rts
  1767.  
  1768. .exit_nf    moveq    #0,d0
  1769.     bra.b    .exit
  1770.  
  1771. .try_rom    tst.l    d6
  1772.     beq.b    .exit_nf
  1773.  
  1774.     move.l    d4,d0
  1775.     move.l    a4,a0
  1776.  
  1777.     move.l    #$01000000,d1
  1778.     sub.l    d0,d1            d2=rom start (rom)
  1779.     move.l    a0,a5
  1780.     sub.l    d1,a5            a5=difference
  1781.  
  1782.     moveq    #0,d6
  1783.     bra.b    .findres
  1784.  
  1785.  
  1786. PATHBUF_SIZE    EQU    256
  1787.  
  1788. ;  IN: a0=ptr to rom (buf), d0=rom len, a3=array  (d6=dosbase)
  1789. ; OUT: d0=success, will print doserror if failed
  1790. DoPlanting    movem.l    d1-a6,-(sp)
  1791.     lea    (-PATHBUF_SIZE,sp),sp
  1792.     move.l    sp,a5
  1793.     move.l    d6,a6
  1794.  
  1795.     move.l    d0,d1
  1796.     move.l    (ARG_MODULE,a3),d0
  1797.     beq    .exit            OK! ;-)
  1798.     move.l    d0,a2
  1799.  
  1800.     IFND    HAVE_NEW_ENV_METHOD
  1801.     moveq    #0,d3
  1802.     ENDC
  1803.     moveq    #0,d4            null!
  1804.     cmp.w    #37,(LIB_VERSION,a6)
  1805.     blo    .not20
  1806.  
  1807.     tst.l    (ARG_IGNPATH,a3)
  1808.     bne    .ignorepath
  1809.  
  1810.     IFD    HAVE_NEW_ENV_METHOD
  1811.  
  1812.     movem.l    d1-d3/a0,-(sp)
  1813.     sub.l    a1,a1
  1814.     move.l    (_ExecBase,pc),a6
  1815.     call    FindTask
  1816.     move.l    d6,a6
  1817.     move.l    d0,a0
  1818.     lea    (pr_WindowPtr,a0),a0
  1819.     move.l    (a0),-(sp)
  1820.     move.l    a0,-(sp)
  1821.     moveq    #-1,d0
  1822.     move.l    d0,(a0)
  1823.  
  1824.     lea    (_VarName,pc),a0
  1825.     move.l    a0,d1
  1826.     move.l    a5,d2
  1827.     move.l    #PATHBUF_SIZE,d3    d4=0
  1828.     call    GetVar
  1829.     addq.l    #1,d0
  1830.     bne.b    .gotvar
  1831.     lea    (_VarEnvArcName,pc),a0
  1832.     move.l    a0,d1
  1833.     call    GetVar
  1834.     addq.l    #1,d0
  1835.     bne.b    .gotvar
  1836.  
  1837.     lea    (_VarEnvArcName,pc),a0
  1838.     move.l    a0,d1
  1839.     move.l    #MODE_OLDFILE,d2
  1840.     call    Open
  1841.     move.l    d0,d4            d4=0 if failed, no dirlock
  1842.     beq.b    .novar
  1843.     move.l    d4,d1
  1844.     move.l    a5,d2
  1845.     subq.l    #1,d3            #PATHBUF_SIZE-1
  1846.     call    Read
  1847.     move.l    d0,d2
  1848.     move.l    d4,d1
  1849.     call    Close
  1850.     tst.l    d2
  1851.     bmi.b    .novar
  1852.     clr.b    0(a5,d2.l)        null terminate
  1853.     move.l    a5,a0            strip linefeeds
  1854. .filt_loop    move.b    (a0)+,d0
  1855.     beq.b    .filt_end
  1856.     cmp.b    #10,d0
  1857.     bne.b    .filt_loop
  1858.     clr.b    -(a0)
  1859. .filt_end
  1860.     IFNE    HAVE_DEFBKMODPATH
  1861.     bra.b    .gotvar
  1862. .novar    lea    (_DefaultBKMODPATH,pc),a0
  1863.     move.l    a5,a1
  1864. .def_cpy    move.b    (a0)+,(a1)+
  1865.     bne.b    .def_cpy
  1866.     ENDC
  1867. .gotvar
  1868.  
  1869.     move.l    a5,d1
  1870.     bsr    _lockread
  1871.     beq.b    .nolock
  1872.     move.l    d1,d4
  1873.     call    CurrentDir
  1874.     move.l    d0,d7            oldlock
  1875. .nolock
  1876.     IFEQ    HAVE_DEFBKMODPATH
  1877. .novar
  1878.     ENDC
  1879.  
  1880.     move.l    (sp)+,a0
  1881.     move.l    (sp)+,(a0)
  1882.  
  1883.     movem.l    (sp)+,d1-d3/a0
  1884. .ignorepath
  1885. .not20
  1886.  
  1887.     ELSE
  1888.  
  1889.     movem.l    d1-d2/a0,-(sp)
  1890.     sub.l    a1,a1
  1891.     move.l    (_ExecBase,pc),a6
  1892.     call    FindTask
  1893.     move.l    d6,a6
  1894.     move.l    d0,a0
  1895.     lea    (pr_WindowPtr,a0),a0
  1896.     move.l    (a0),-(sp)
  1897.     move.l    a0,-(sp)
  1898.     moveq    #-1,d0
  1899.     move.l    d0,(a0)
  1900.  
  1901.     lea    (_EnvName,pc),a0
  1902.     move.b    #':',(3,a0)
  1903.     move.l    a0,d1
  1904.     bsr    _lockread
  1905.     move.l    d0,d2
  1906.     call    UnLock
  1907.     move.l    (sp)+,a0
  1908.     move.l    (sp)+,(a0)
  1909.     tst.l    d2
  1910.     bne.b    .has_env
  1911.  
  1912.     lea    (_EnvArcName,pc),a0
  1913.     move.l    a0,d1
  1914.     bsr    _lockread
  1915.     beq.b    .no_envarclock
  1916.     move.l    d0,d2
  1917.     lea    (_EnvName,pc),a0
  1918.     clr.b    (3,a0)
  1919.     move.l    a0,d1
  1920.     call    AssignLock
  1921.     move.l    d0,d3            d3=assignstate
  1922.     bne.b    .got_assign
  1923.     move.l    d2,d1
  1924.     call    UnLock
  1925. .got_assign
  1926. .no_envarclock
  1927. .has_env
  1928.     lea    (_VarName,pc),a0
  1929.     move.l    a0,d1
  1930.     move.l    a5,d2
  1931.     move.l    d3,-(sp)
  1932.     move.l    #PATHBUF_SIZE,d3    d4=0
  1933.     call    GetVar
  1934.     move.l    (sp)+,d3
  1935.     addq.l    #1,d0
  1936.     beq.b    .novar
  1937.     move.l    a5,d1
  1938.     bsr    _lockread
  1939.     beq.b    .nolock
  1940.     move.l    d0,d4
  1941.     move.l    d4,d1
  1942.     call    CurrentDir
  1943.     move.l    d0,d7            oldlock
  1944. .nolock
  1945. .novar    movem.l    (sp)+,d1-d2/a0
  1946. .not20
  1947.     ENDC
  1948.  
  1949. .loop    move.l    (a2)+,d0
  1950.     beq.b    .exit2
  1951.     move.l    d0,a1
  1952.     move.l    d1,d0
  1953.     bsr.b    FilePlant
  1954.     bne.b    .loop
  1955.     bsr    _PrintFault        IN: d5=kickflag, d6=dosbase
  1956.     lea    (PlantError,pc),a0
  1957.     move.l    a2,a1
  1958.     subq.l    #4,a1
  1959.     bsr    _Printf
  1960.     moveq    #-1,d0
  1961.  
  1962. .exit2    tst.l    d4
  1963.     beq.b    .nodirlock
  1964.     move.l    d0,-(sp)
  1965.     move.l    d7,d1
  1966.     call    CurrentDir
  1967.     move.l    d4,d1
  1968.     call    UnLock
  1969.     move.l    (sp)+,d0
  1970. .nodirlock
  1971.     IFND    HAVE_NEW_ENV_METHOD
  1972.  
  1973.     tst.l    d3
  1974.     beq.b    .noassign
  1975.     move.l    d0,d7
  1976.     lea    (_EnvName,pc),a0
  1977.     clr.b    (3,a0)
  1978.     move.l    a0,d1
  1979.     moveq    #0,d2
  1980.     call    AssignLock
  1981.     move.l    d7,d0
  1982. .noassign
  1983.     ENDC
  1984.  
  1985. .exit    not.l    d0
  1986.     lea    (PATHBUF_SIZE,sp),sp
  1987.     movem.l    (sp)+,d1-a6
  1988.     rts
  1989.  
  1990. _lockread    moveq    #ACCESS_READ,d2
  1991.     call    Lock
  1992.     move.l    d0,d1
  1993.     rts
  1994.  
  1995. ;  IN: a1=ptr to filename, a0=ptr to rom (buf), d0=rom len  (d6=dosbase)
  1996. ; OUT: d0=success
  1997. FilePlant    movem.l    d1-a6,-(sp)
  1998.     move.l    d6,a6
  1999.     moveq    #0,d7
  2000.  
  2001.     move.l    d0,d4
  2002.     move.l    a0,a4
  2003.  
  2004.     ; this is a elfloadseg-patch ioerr bug
  2005.     ; workaround:
  2006.  
  2007.     move.l    a1,a2
  2008.     move.l    a1,d1
  2009.     moveq    #ACCESS_READ,d2
  2010.     call    Lock
  2011.     move.l    d0,d1
  2012.     beq.b    .exit
  2013.     call    UnLock
  2014.  
  2015.     move.l    a2,d1
  2016.     call    LoadSeg
  2017.     move.l    d0,d5
  2018.     beq.b    .exit
  2019.  
  2020.     move.l    d5,a1
  2021.     add.l    a1,a1
  2022.     addq.l    #2,a1            ;-)
  2023.     add.l    a1,a1
  2024.     move.l    d4,d0
  2025.     move.l    a4,a0
  2026.     bsr    InstallModule
  2027.     move.l    d0,d7
  2028.     bne.b    .was_module
  2029.  
  2030.     ; try direct executable planting
  2031.  
  2032.     cmp.l    #BKMODULE_ID,(a1)    was it a module that failed?
  2033.     beq.b    .was_module        yes, quit!
  2034.  
  2035.     ; the test above is really needed or else horrors
  2036.     ; would happen. namely installing non-functional
  2037.     ; resident tag that would crash system.
  2038.  
  2039.     move.l    (8*4,sp),d1        filename from stack
  2040.     move.l    #MODE_OLDFILE,d2
  2041.     call    Open
  2042.     move.l    d0,d4
  2043.     beq.b    .exit
  2044.  
  2045.     lea    (.af_dosbase,pc),a0
  2046.     move.l    a6,(a0)
  2047.  
  2048.     pea    (.freefunc,pc)
  2049.     pea    (.allocfunc,pc)
  2050.     pea    (.readfunc,pc)
  2051.     move.l    sp,a1
  2052.     clr.l    -(sp)
  2053.     move.l    sp,a2
  2054.     sub.l    a0,a0
  2055.     ;move.l    d4,d0            d0=filehandle!!
  2056.     call    InternalLoadSeg
  2057.     lea    (4*4,sp),sp
  2058.     move.l    d0,d7
  2059.  
  2060.     move.l    d4,d1
  2061.     call    Close
  2062.     
  2063. .was_module    move.l    d5,d1
  2064.     beq.b    .exit
  2065.     call    UnLoadSeg
  2066. .exit    move.l    d7,d0
  2067.     movem.l    (sp)+,d1-a6
  2068.     rts
  2069.  
  2070.  
  2071.  
  2072. ;  IN: d0=size, d1=flags
  2073. ; OUT: d0=memory
  2074. .allocfunc    tst.l    d0
  2075.     bne.b    .af_do
  2076.  
  2077. .af_fail    move.l    a6,-(sp)
  2078.     move.l    (.af_dosbase,pc),a6
  2079.     moveq    #ERROR_NO_FREE_STORE,d1
  2080.     call    SetIoErr
  2081.     move.l    (sp)+,a6
  2082.     moveq    #0,d0
  2083.     rts
  2084.  
  2085. .af_do    btst    #MEMB_CHIP,d1        don't allow chipmem
  2086.     bne.b    .af_fail
  2087.  
  2088.     movem.l    d0/d1,-(sp)
  2089.     move.l    (_erh_memheader,pc),d0
  2090.     beq.b    .af_exit
  2091.     move.l    d0,a0
  2092.     move.l    (sp),d0
  2093.     call    Allocate
  2094.     tst.l    d0
  2095.     beq.b    .af_nomem
  2096.     ; d0=return val
  2097.  
  2098.     ; should clear allocated area?
  2099.     btst    #MEMB_CLEAR-16,(1,sp)
  2100.     beq.b    .af_exit
  2101.  
  2102.     ; get original alloc req and align it
  2103.     move.l    (sp),d1
  2104.     addq.l    #MEM_BLOCKMASK,d1
  2105.     and.w    #-MEM_BLOCKSIZE,d1
  2106.  
  2107.     move.l    d0,a0
  2108. .af_clear    clr.l    (a0)+
  2109.     clr.l    (a0)+
  2110.     subq.l    #8,d1
  2111.     bne.b    .af_clear
  2112.  
  2113. .af_exit    addq.l    #8,sp
  2114.     rts
  2115.  
  2116. .af_nomem    addq.l    #8,sp
  2117.     bra.b    .af_fail
  2118.  
  2119. .af_dosbase    ds.l    1
  2120.  
  2121.  
  2122. ;  IN: a1=memory d0=size
  2123. ; OUT: -
  2124. .freefunc    tst.l    d0
  2125.     bne.b    .ff_do
  2126. .ff_no    rts
  2127. .ff_do    move.l    a1,d1
  2128.     beq.b    .ff_no
  2129.  
  2130.     move.l    (_erh_memheader,pc),d1
  2131.     beq.b    .ff_no
  2132.  
  2133.     movem.l    d0/a1,-(sp)
  2134.     move.l    a1,d1
  2135.     and.w    #-MEM_BLOCKSIZE,d1
  2136.     exg    d1,a1
  2137.     addq.l    #MEM_BLOCKMASK,d0
  2138.     sub.l    a1,d1
  2139.     add.l    d1,d0
  2140.     moveq    #-1,d1
  2141.     and.l    #-MEM_BLOCKSIZE,d0    note: .l!!
  2142.     beq.b    .ff_nofill
  2143. .ff_fill    move.l    d1,(a1)+
  2144.     move.l    d1,(a1)+
  2145.     subq.l    #8,d0
  2146.     bne.b    .ff_fill
  2147. .ff_nofill    movem.l    (sp)+,d0/a1
  2148.  
  2149.     move.l    (_erh_memheader,pc),a0
  2150.     jmp    (_LVODeallocate,a6)
  2151.  
  2152. ;  IN: d1=fh, d2=buffer, d3=len
  2153. ; OUT: d0=actual
  2154. .readfunc    jmp    (_LVORead,a6)
  2155.  
  2156.  
  2157.  
  2158. ;  IN: d1.l=error (d6=dosbase)
  2159. SetIoErr    movem.l    d0-d1/a0-a1/a6,-(sp)
  2160.     move.l    d6,a6
  2161.     cmp.w    #36,(LIB_VERSION,a6)
  2162.     blo.b    .old
  2163.     call    SetIoErr
  2164.     bra.b    .exit
  2165. .old    move.l    (_ExecBase,pc),a6
  2166.     sub.l    a1,a1
  2167.     call    FindTask
  2168.     move.l    d0,a0
  2169.     move.l    (4,sp),(pr_Result2,a0)
  2170. .exit    movem.l    (sp)+,d0-d1/a0-a1/a6
  2171.     rts
  2172.  
  2173.  
  2174. ;  IN: a1=ptr to module, a0=ptr to rom (buf), d0=rom len  (d6=dosbase)
  2175. ; OUT: d0=success, d1/a0/a1 preserved
  2176. InstallModule    movem.l    d1-a6,-(sp)
  2177.     moveq    #0,d7
  2178.     move.l    #ERROR_OBJECT_WRONG_TYPE,d1
  2179.     bsr.b    SetIoErr
  2180.  
  2181.     move.l    #$01000000,d2
  2182.     sub.l    d0,d2
  2183.     move.l    a0,a5
  2184.     sub.l    d2,a5            a5=difference
  2185.  
  2186.     cmp.l    #BKMODULE_ID,(a1)+    (bkm_ID)
  2187.     bne.b    .exit
  2188.     move.w    (a1)+,d4        d4=bkm_Flags, a1=bkm_ResTag
  2189.     move.w    d4,d1
  2190.     and.w    #~BKMF_ALL,d1        Test validity:
  2191.     bne.b    .exit
  2192.     cmp.w    #BKEP_ID,(a1)        Test for patch module:
  2193.     beq    .is_epatch
  2194.     cmp.l    #RTC_MATCHWORD<<16,(a1)
  2195.     bne.b    .exit
  2196.  
  2197.     move.l    #ERROR_OBJECT_TOO_LARGE,d1
  2198.     bsr.b    SetIoErr
  2199.  
  2200.     lea    (.replace_test,pc),a3
  2201.     lsr.w    #1,d4            btst    #BKMB_ReplaceMode,d4
  2202.     bcs.b    .replace
  2203.     lea    (.single_test,pc),a3
  2204.     lsr.w    #1,d4            btst    #BKMB_SingleMode,d4
  2205.     bcc.b    .no_findresident
  2206. .replace    movem.l    d0/a1,-(sp)
  2207.     add.l    (RT_NAME,a1),a1
  2208.     bsr    FindResident
  2209.     move.l    d0,a2
  2210.     movem.l    (sp)+,d0/a1
  2211.     jmp    (a3)
  2212. .no_findresident
  2213. .is_single
  2214. .is_erbf    move.l    (RT_ENDSKIP,a1),d1
  2215.     lsr.w    #1,d4            btst    #BKMB_ExtResBuf,d4
  2216.     bcc.b    .no_extresbuf1
  2217.     neg.l    d1
  2218. .no_extresbuf1    bsr    FindSpace
  2219.     beq.b    .exit
  2220.  
  2221. .go_replace    move.l    d0,a3            a3=ptr to func (buf)
  2222.     move.l    d1,a2            a2=ptr to func (ROM)
  2223.  
  2224.     move.w    ($C,a0),d1        d1=rom version
  2225.     move.l    a1,a0
  2226.     lea    (RT_VERSION,a0),a4
  2227.     cmp.b    (a4),d1            Test version!
  2228.     blo.b    .nofail
  2229.     move.b    d1,(a4)            Force current version!
  2230.     cmp.w    #36,d1
  2231.     shs    d1
  2232.     move.l    a3,a1            a2=ptr to func (ROM)
  2233.     bsr    PutResident
  2234.  
  2235. .nofail    moveq    #1,d7
  2236. .exit    move.l    d7,d0
  2237. .exit2    bsr    CacheClearOS        Clear caches.
  2238.     movem.l    (sp)+,d1-a6
  2239.     rts
  2240.  
  2241.  
  2242. .replace_test    beq.b    .exit            If no match exit!
  2243.     move.b    (RT_PRI,a2),d1
  2244.     cmp.b    (RT_PRI,a1),d1
  2245.     bne.b    .exit            If no match exit!
  2246.  
  2247.     lsr.w    #1,d4
  2248.     btst    #0,d4            btst BKMB_ExtResBuf,d4
  2249.     bne.b    .is_erbf
  2250.  
  2251.     move.l    (RT_ENDSKIP,a2),d1    d1=ptr to ENDSKIP (ROM)
  2252.     add.l    a5,d1            d1=ptr to ENDSKIP (buf)
  2253.     sub.l    a2,d1
  2254.     cmp.l    (RT_ENDSKIP,a1),d1
  2255.     ble.b    .exit
  2256.     move.l    a2,d0
  2257.     move.l    d0,d1
  2258.     sub.l    a5,d1
  2259.     bra.b    .go_replace
  2260.  
  2261.  
  2262. .single_test    beq.b    .is_single        SINGLE: If no match continue!
  2263.     move.b    (RT_PRI,a2),d1
  2264.     cmp.b    (RT_PRI,a1),d1
  2265.     bne.b    .is_single        SINGLE: If no match continue!
  2266.     move.l    #ERROR_TOO_MANY_ARGS,d1
  2267.     bsr    SetIoErr
  2268.     bra.b    .exit
  2269.  
  2270. ; a0=ptr to rom start (buf), a1=ptr to epatch, d0=rom len, d2=ptr to rom start (ROM)
  2271. .is_epatch    lea    (2,a1),a5
  2272.     move.l    d2,a1
  2273.     lea    (FindResident,pc),a2
  2274.     lea    (InstallModule,pc),a3
  2275.     lea    (_Printf,pc),a4
  2276.     move.l    (_ExecBase,pc),a6
  2277.     jsr    (a5)
  2278.     bra.b    .exit2
  2279.  
  2280.  
  2281. ;  IN: a0=rom (buf), d0=rom len, d1=required space (negate if ExtResBuf required)
  2282. ; OUT: d0=ptr to area (buf) or NULL, d1=ptr to area (rom)
  2283. ;NOTE: condition codes set on return!
  2284. FindSpace    movem.l    d2-d3/d6-d7/a0-a2,-(sp)
  2285.     moveq    #0,d7
  2286.  
  2287.     move.l    #$01000000,d2
  2288.     sub.l    d0,d2
  2289.     move.l    a0,d6
  2290.     sub.l    d2,d6            d6=difference (buf-rom)
  2291.  
  2292.     tst.l    d1
  2293.     bmi.b    .required_extres
  2294.  
  2295.     lea    ROMSUMOFFS(a0,d0.l),a1
  2296.     bsr.b    .find
  2297.     bhs.b    .found            Big enough 'empty' space.
  2298.  
  2299.     move.l    #$00040000,d2
  2300.     cmp.l    d2,d0            Test for >$40000 ROM
  2301.     bls.b    .try_extres
  2302.  
  2303.     lea    (a0,d0.l),a1
  2304.     sub.l    d2,a1            a1=$FC0000
  2305.     move.l    (a1),d2
  2306.     and.l    #$FFF8FFFF,d2
  2307.     cmp.l    #$11104EF9,d2
  2308.     bne.b    .try_extres
  2309.     bsr.b    .find
  2310.     blo.b    .try_extres
  2311.  
  2312. .found    move.l    a1,d7
  2313.     addq.l    #1+3,d7
  2314.     and.w    #-4,d7
  2315.  
  2316. .exit    move.l    d7,d1
  2317.     sub.l    d6,d1
  2318.     move.l    d7,d0
  2319.     movem.l    (sp)+,d2-d3/d6-d7/a0-a2
  2320.     rts
  2321.  
  2322. .find    moveq    #-1,d2
  2323. .null    move.b    -(a1),d3
  2324.     addq.l    #1,d2
  2325.     not.b    d3
  2326.     beq.b    .null
  2327.     cmp.l    d1,d2
  2328.     rts
  2329.  
  2330. .required_extres
  2331.     neg.l    d1
  2332. .try_extres    move.l    (_erh_memheader,pc),d0
  2333.     beq.b    .exit
  2334.     move.l    d0,a0
  2335.     move.l    d1,d0
  2336.     move.l    a6,-(sp)
  2337.     move.l    (_ExecBase,pc),a6
  2338.     call    Allocate
  2339.     move.l    (sp)+,a6
  2340.     move.l    d0,d7
  2341.     moveq    #0,d6            NULL difference!
  2342.     bra.b    .exit
  2343.  
  2344.  
  2345. ;  IN: a0=resident
  2346. ;      a1=adr to "free" buf
  2347. ;      a2=adr to "free" buf (rom)
  2348. ;      d1.b=zero if <V36 ROM
  2349. PutResident    ;bsr    CacheClearOS        336r: Added coz bad move16 optimized copymem patches?
  2350.     movem.l    d0-a6,-(sp)
  2351.     move.l    (_ExecBase,pc),a6
  2352.     lea    (RT_MATCHTAG,a1),a3
  2353.     lea    (4,a1),a4
  2354.     move.l    (RT_ENDSKIP,a0),d0
  2355.     call    CopyMem
  2356.     ;bsr    CacheClearOS        336r: Added coz bad move16 optimized copymem patches?
  2357.     move.l    a2,d0
  2358.     move.l    d0,(a3)+        RT_MATCHTAG
  2359.     add.l    d0,(a3)+        RT_ENDSKIP
  2360.     tst.b    (4+3,sp)        V36+ ?
  2361.     bne.b    .no_incomp
  2362.     move.b    (a3),d1
  2363.     and.b    #~(RTF_AUTOINIT!RTW_COLDSTART),d1
  2364.     beq.b    .no_incomp
  2365.     and.b    #RTF_AUTOINIT!RTW_COLDSTART,(a3) Mask out incompatible bits
  2366.     or.b    #RTW_COLDSTART,(a3)
  2367. .no_incomp    move.b    (a3),d1
  2368.     addq.l    #RT_NAME-RT_FLAGS,a3
  2369.     add.l    d0,(a3)+        RT_NAME
  2370.     add.l    d0,(a3)+        RT_IDSTRING
  2371.     and.b    #RTF_AUTOINIT,d1
  2372.     beq.b    .noauto
  2373.     add.l    (a3),a4
  2374.     tst.l    (a4)+
  2375.     beq.b    .nop1
  2376.     add.l    d0,(-4,a4)
  2377. .nop1
  2378.     tst.l    (a4)+
  2379.     beq.b    .nop2
  2380.     add.l    d0,(-4,a4)
  2381. .nop2
  2382.     tst.l    (a4)+
  2383.     beq.b    .nop3
  2384.     add.l    d0,(-4,a4)
  2385. .nop3
  2386. .noauto    add.l    d0,(a3)+        RT_INIT
  2387.     movem.l    (sp)+,d0-a6
  2388.     rts
  2389.  
  2390.  
  2391. ;  IN: a0=rom (buf), d0=rom len, d1=required buffer len, d2=sanity size
  2392. ;      a6=execbase, d6=dosbase
  2393. ; OUT: d0=ptr to extres buffer or NULL
  2394. ExtResBuf    movem.l    d0-a6,-(sp)
  2395.     moveq    #0,d7
  2396.  
  2397.     move.l    d0,d5            d5=rom len
  2398.     move.l    a0,a5            a0=buf strt
  2399.  
  2400.     move.l    #ERROR_OBJECT_WRONG_TYPE,d1
  2401.     bsr    SetIoErr
  2402.  
  2403.     cmp.w    #37,($C,a5)        need 37+
  2404.     blo    .exit
  2405.  
  2406.     move.b    (_MemHeaderFlag,pc),d0
  2407.     beq    .exit
  2408.  
  2409.     ; find exec.library resident tag
  2410.  
  2411.     move.l    a5,a0
  2412.     move.l    d5,d0
  2413.     lea    (.execname,pc),a1
  2414.     bsr    FindResident
  2415.     tst.l    d0
  2416.     beq    .exit
  2417.  
  2418.     move.l    d0,a3
  2419.     move.l    (RT_INIT,a3),d1
  2420.  
  2421.     ;test if inside rom bounds?
  2422.     cmp.l    #$0f80000,d1
  2423.     blo    .exit
  2424.     cmp.l    #$1000000,d1
  2425.     bhs    .exit
  2426.  
  2427.     ; generate ram buffer address
  2428.     sub.l    #$f80000,d1        -$f80000
  2429.     add.l    a5,d1            +buffer
  2430.     move.l    d1,a0
  2431.  
  2432.     moveq    #12,d4            skip 12 bytes
  2433.     cmp.l    #$41F900DF,(a0)        37.x
  2434.     beq.b    .use12
  2435.     moveq    #4,d4            skip 4 bytes
  2436.     cmp.w    #$41FA,(a0)        39.x/40.x
  2437.     bne    .exit
  2438. .use12    add.l    (RT_INIT,a3),d4
  2439.  
  2440.     move.l    #extreshandler_SIZEOF+ERHANDLER_SIZEOF+8+MH_SIZE+7,d0
  2441.     add.l    (1*4,sp),d0        d1 from stack
  2442.     and.w    #-8,d0            align by 8
  2443.  
  2444.     ; use this to set up MH_UPPER, MH_FREE,
  2445.     ; MC_BYTES, ScanEnd...
  2446.     move.l    d0,d2
  2447.     sub.l    #extreshandler_SIZEOF,d2
  2448.  
  2449.     ; len for allocabs
  2450.     move.l    d0,d3
  2451.  
  2452.     ; add sanity just in case (something in boot could alloc
  2453.     ; MEMF_REVERSE overwriting us...)
  2454.     ;
  2455.     ; If user sees 80010000 alert he/she should increase
  2456.     ; SANITY
  2457.  
  2458.     add.l    #$90000,d0        add 576k... (internal sanity)
  2459.     add.l    (2*4,sp),d0        d2 from stack
  2460.  
  2461.     lea    (_erh_alloclen,pc),a0
  2462.     move.l    d0,(a0)
  2463.  
  2464.     call    Forbid
  2465.     lea    (_memhead,pc),a0
  2466.     bsr    FindMemHeader
  2467.     beq    .cantfind
  2468.     bsr    Allocate_REVERSE
  2469.     ;call    Allocate
  2470.     call    Permit
  2471.     lea    (_erh_freeaddr,pc),a0
  2472.     move.l    d0,(a0)
  2473.     beq    .exit
  2474.  
  2475.     move.l    d0,a2
  2476.     move.l    d0,a1
  2477.     addq.l    #8,a2            jump over two longs
  2478.  
  2479.     lea    (extreshandler,pc),a0
  2480.     moveq    #extreshandler_SIZEOF,d0
  2481.     call    CopyMem
  2482.  
  2483.     lea    (extreshandler_SIZEOF-8,a2),a0
  2484.     move.l    a0,d0
  2485.  
  2486.     lea    (_erh_memheader,pc),a1
  2487.     move.l    a0,(a1)
  2488.     lea    (MH_SIZE,a0),a1
  2489.     clr.l    (a0)+            LN_SUCC
  2490.     clr.l    (a0)+            LN_PRED
  2491.     move.w    #NT_MEMORY<<8,(a0)+    LN_TYPE, LN_PRI
  2492.     clr.l    (a0)+            LN_NAME
  2493.     clr.w    (a0)+            MH_ATTRIBUTES
  2494.     move.l    a1,(a0)+        MH_FIRST
  2495.     move.l    a1,(a0)+        MH_LOWER
  2496.     add.l    d2,d0            d0 = a1 - (MH_SIZE+8) + size
  2497.     move.l    d0,(a0)+        MH_UPPER
  2498.     moveq    #-(MH_SIZE+8),d0
  2499.     add.l    d2,d0
  2500.     move.l    d0,(a0)+        MH_FREE
  2501.     move.l    a0,d7
  2502.     clr.l    (a0)+            MC_NEXT
  2503.     move.l    d0,(a0)+        MC_BYTES
  2504.  
  2505.     subq.l    #8,d0
  2506.     moveq    #-1,d1
  2507. .fill    move.l    d1,(a0)+
  2508.     move.l    d1,(a0)+
  2509.     subq.l    #8,d0
  2510.     bne.b    .fill
  2511.  
  2512.  
  2513.     move.l    a2,d0
  2514.     lea    (allocpt+2,pc),a0
  2515.     subq.l    #8,d0
  2516.     move.l    d0,(a0)
  2517.     lea    (alloclen+2,pc),a0
  2518.     move.l    d3,(a0)
  2519.  
  2520.     move.l    d7,(scanstartoffs-8,a2)
  2521.     lea    (_erh_areastart,pc),a0
  2522.     move.l    d7,(a0)
  2523.     moveq    #-(MH_SIZE+8),d0
  2524.     add.l    d2,d0
  2525.     lea    (_erh_arealen,pc),a0
  2526.     move.l    d0,(a0)
  2527.     add.l    d7,d0
  2528.     move.l    d0,(scanendoffs-8,a2)
  2529.     move.l    d4,(jumpoffs-8,a2)
  2530.     move.l    a2,(RT_INIT,a3)
  2531.  
  2532.  
  2533.     move.l    a5,a0            a0=ptr to rom (buf)
  2534.     move.l    d5,d0            d0=rom len
  2535.     lea    (_erhandler_module,pc),a1
  2536.     bsr    InstallModule
  2537.     tst.l    d0
  2538.     bne.b    .exit
  2539.  
  2540.     bsr    FreeExtResBuf
  2541.     moveq    #0,d7
  2542.  
  2543.  
  2544. .exit    move.l    d7,d0
  2545.     addq.l    #4,sp
  2546.     movem.l    (sp)+,d1-a6
  2547.     rts
  2548.  
  2549. .cantfind    call    Permit
  2550.     bra.b    .exit
  2551.  
  2552.  
  2553. .execname    dc.b    'exec.library',0
  2554.     CNOP    0,2
  2555.  
  2556.     ; IN: a6=execbase
  2557. extreshandler    dc.l    0,0            don't trust 8 bytes we AllocAbs
  2558.  
  2559.     lea    (.areas,pc),a0
  2560.     dc.w    $4ef9
  2561. jumpoffs    EQU    *-extreshandler
  2562.     dc.l    $badc0de
  2563.  
  2564.  
  2565. .areas    dc.l    $0F80000
  2566.     dc.l    $1000000
  2567.     dc.l    $0F00000
  2568.     dc.l    $0F80000
  2569. scanstartoffs    EQU    *-extreshandler
  2570.     dc.l    $15c0ded
  2571. scanendoffs    EQU    *-extreshandler
  2572.     dc.l    $badd1e
  2573.     dc.l    -1
  2574.  
  2575. extreshandler_SIZEOF    EQU    (*-extreshandler+7)&-8
  2576.  
  2577.  
  2578.  
  2579.  
  2580. ;  IN: a0 = memHeader
  2581. ;      d0 = byteSize
  2582. ;      a6 = execbase
  2583. ; OUT: d0 = memoryBlock or null, z set/clr
  2584. Allocate_REVERSE
  2585.     jsr    (_LVOForbid,a6)
  2586.     move.l    (MH_FIRST,a0),d1
  2587.     beq.b    .fail
  2588.  
  2589.     sub.l    a1,a1            ; default
  2590.  
  2591.     ; find last MH that matches our requirements
  2592. .findfree_r    move.l    d1,a0
  2593.     cmp.l    (MC_BYTES,a0),d0
  2594.     bhi.b    .findskip_r
  2595.     move.l    a0,a1
  2596. .findskip_r    move.l    (a0),d1            ; MC_NEXT
  2597.     bne.b    .findfree_r
  2598.  
  2599.     ; found any?
  2600.     move.l    a1,d1
  2601.     beq.b    .fail
  2602.  
  2603.     ; allocate from it!
  2604.     move.l    (MC_BYTES,a1),d1
  2605.     sub.l    d0,d1
  2606.     and.w    #-MEM_BLOCKSIZE,d1
  2607.     add.l    d1,a1
  2608.     jsr    (_LVOAllocAbs,a6)
  2609.     jsr    (_LVOPermit,a6)
  2610.     tst.l    d0
  2611.     rts
  2612.  
  2613. .fail    jsr    (_LVOPermit,a6)
  2614.     moveq    #0,d0
  2615.     rts
  2616.  
  2617.  
  2618.  
  2619.     STRUCTURE BKERHSS,0
  2620.     STRUCT    BKERHSS_ss,SS_SIZE
  2621.     ULONG    BKERHSS_version
  2622.     UWORD    BKERHSS_unused0
  2623.     APTR    BKERHSS_memheader
  2624.     LABEL    BKERHSS_SIZEOF
  2625.  
  2626. _erhandler_module
  2627.  BK_MOD BKMF_SingleMode|BKMF_ExtResBuf,_erhandler_end,(RTF_COLDSTART)<<24!37<<16!NT_UNKNOWN<<8!104,_erh_name,_erh_name,_ERHandler
  2628. ;
  2629. ; IMPORTANT:
  2630. ; priority is after `diag init' resident that adds memory to system
  2631. ;
  2632.  
  2633.     ; d0=0, a0=0, a6=execbase
  2634. _ERHandler    ; reallocate EXTRESBUF
  2635. allocpt    lea    $deadc0de,a1
  2636. alloclen    move.l    #$cafecafe,d0
  2637.     call    AllocAbs
  2638.     tst.l    d0
  2639.     bne.b    .got
  2640.  
  2641.     ; die horribe death
  2642.     move.l    #AT_DeadEnd!AG_NoMemory,d7
  2643.     call    Alert
  2644. .got
  2645.  
  2646.     ; initialize EXTRES API...
  2647.  
  2648.     moveq    #BKERHSS_SIZEOF,d0
  2649.     moveq    #MEMF_ANY,d1
  2650.     call    AllocMem
  2651.     tst.l    d0
  2652.     beq.b    .nomem
  2653.  
  2654.     move.l    d0,-(sp)
  2655.     move.l    d0,a0
  2656.     call    InitSemaphore
  2657.     move.l    (sp)+,a1
  2658.     move.l    #ERH_API_V1,(BKERHSS_version,a1)
  2659.     clr.w    (BKERHSS_unused0,a1)
  2660.  
  2661.     ; must not optimize this!
  2662. _erh_memheader    EQU    *+2
  2663.     move.l    #0,(BKERHSS_memheader,a1)
  2664.  
  2665.     lea    (_erh_name,pc),a0
  2666.     move.l    a0,(LN_NAME,a1)
  2667.     move.b    #-120,(LN_PRI,a1)
  2668.  
  2669.     call    AddSemaphore
  2670. .nomem
  2671.     ; fall thru!
  2672.  
  2673.     ;bsr.b    MoveChipHeader
  2674.     ;rts
  2675.  
  2676. ; Routines taken from FastExec 2.5 public domain source code by
  2677. ; Torbjörn A. Andersson. Modified by Harry Sintonen.
  2678. ******************************************************************************
  2679.  
  2680. MoveChipHeader    movem.l    d2/a2-a3,-(sp)
  2681.     call    Forbid
  2682.  
  2683. .loop0    move.l    (MemList,a6),d2
  2684.  
  2685. .loop1    move.l    d2,a2
  2686.     move.l    (a2),d2
  2687.     beq.b    .quit
  2688.  
  2689.     cmp.l    #$1000000,a2        ; address
  2690.     bhs.b    .loop1
  2691.  
  2692.     moveq    #MH_SIZE,d0
  2693.     moveq    #MEMF_PUBLIC!MEMF_FAST,d1
  2694.     call    AllocMem
  2695.     tst.l    d0
  2696.     beq.b    .quit
  2697.     move.l    d0,a3
  2698.  
  2699.     lea    (LN_TYPE,a2),a0        ; source
  2700.     lea    (LN_TYPE,a3),a1        ; dest
  2701.     moveq    #MH_SIZE-LN_TYPE,d0
  2702.     call    CopyMem
  2703.  
  2704.     lea    (MH_SIZE,a2),a0
  2705.     cmp.l    (MH_LOWER,a2),a0
  2706.     bne.b    .ok
  2707.     move.l    a2,(MH_LOWER,a3)
  2708. .ok
  2709.     move.l    a2,a1            ; node
  2710.     call    Remove
  2711.     lea    (MemList,a6),a0        ; list
  2712.     move.l    a3,a1            ; node
  2713.     call    Enqueue
  2714.  
  2715. ;    cmp.w    #36,(LIB_VERSION,a6)
  2716. ;    blo.b    .loop0
  2717.  
  2718.     move.l    a2,a1            ; memoryBlock
  2719.     moveq    #MH_SIZE,d0
  2720.  
  2721.     move.l    d0,d1
  2722.     add.l    a1,d1
  2723.     lea    (MemList,a6),a0
  2724. .floop    move.l    (a0),a0
  2725.     tst.l    (a0)
  2726.     beq.b    .fdone
  2727.     cmp.l    (MH_LOWER,a0),a1
  2728.     blo.b    .floop
  2729.     cmp.l    (MH_UPPER,a0),a1
  2730.     bhs.b    .floop
  2731.     cmp.l    (MH_UPPER,a0),d1
  2732.     bhi.b    .fdone
  2733.     call    FreeMem
  2734. .fdone    bra.b    .loop0
  2735.  
  2736. .quit    call    Permit
  2737.     movem.l    (sp)+,d2/a2-a3
  2738.     rts
  2739.  
  2740. _erh_name    dc.b    'EXTRES Handler',0
  2741.     CNOP    0,2
  2742. _erhandler_end
  2743. ERHANDLER_SIZEOF EQU    (*-_erhandler_module+7)&-8
  2744.  
  2745.  
  2746. CacheClearOS    movem.l    d0-d1/a0-a1/a6,-(sp)
  2747.     pea    (.cleanexit,pc)
  2748.     move.l    (_ExecBase,pc),a6
  2749.     cmp.w    #37,(LIB_VERSION,a6)
  2750.     blo.b    CacheClear
  2751.     jmp    (_LVOCacheClearU,a6)    OK! ;-)
  2752. .cleanexit    movem.l    (sp)+,d0-d1/a0-a1/a6
  2753.     rts
  2754. CacheClear    movem.l    a5/a6,-(sp)
  2755.     lea    (.cacheclrsv,pc),a5
  2756.     move.l    (_ExecBase,pc),a6
  2757.     call    Supervisor
  2758.     movem.l    (sp)+,a5/a6
  2759.     rts
  2760. .cacheclrsv    or.w    #$700,sr        Disable interrupts
  2761.     bsr.b    CacheClrS
  2762.     nop
  2763.     rte
  2764. CacheClrS    btst    #AFB_68020,(_AttnFlags+1,pc)
  2765.     beq.b    .nocache
  2766.     btst    #AFB_68040,(_AttnFlags+1,pc)
  2767.     beq.b    .not040
  2768.     cpusha    bc
  2769.     cinva    bc
  2770.     nop
  2771. .nocache    rts
  2772. .not040    move.l    d0,-(sp)
  2773.     movec    cacr,d0
  2774.     or.w    #CACRF_ClearI!CACRF_ClearD,d0
  2775.     movec    d0,cacr
  2776.     move.l    (sp)+,d0
  2777.     rts
  2778.  
  2779.  
  2780.     IFGT    0
  2781. DisableCache    btst    #AFB_68020,(_AttnFlags+1,pc)
  2782.     beq.b    .no68020
  2783.     movem.l    a5/a6,-(sp)
  2784.     lea    (.discachesv,pc),a5
  2785.     move.l    (_ExecBase,pc),a6
  2786.     call    Supervisor
  2787.     movem.l    (sp)+,a5/a6
  2788. .no68020    rts
  2789. .discachesv    or.w    #$700,sr        Disable interrupts
  2790.     bsr.b    DisableCacheS
  2791.     nop
  2792.     rte
  2793.     ENDC
  2794.  
  2795. DisableCacheS    move.l    d0,-(sp)
  2796.     movec    cacr,d0
  2797.  
  2798.     btst    #AFB_68040,(_AttnFlags+1,pc)
  2799.     bne.b    .is040
  2800.  
  2801.     and.w    #~(CACRF_EnableI!CACRF_IBE!CACRF_EnableD!CACRF_DBE),d0
  2802.     or.w    #CACRF_ClearI!CACRF_ClearD,d0
  2803.     movec    d0,cacr
  2804.  
  2805.     move.l    (sp)+,d0
  2806.     rts
  2807.  
  2808. .is040
  2809.     and.l    #~CACRF_CachesOr060,d0
  2810.     or.l    #CACRF_ClearAllBCache,d0
  2811.     nop
  2812.     cpusha    bc
  2813.     nop
  2814.     cinva    bc
  2815.     nop
  2816.     movec    d0,cacr
  2817.     nop
  2818.  
  2819.     ; turn off 060 superscalar dispatch
  2820.     tst.b    (_AttnFlags+1,pc)
  2821.     bpl.b    .no060
  2822.     dc.w    $4E7A,$0808    movec    pcr,d0
  2823.     and.l    #PCRF_EnableDebugFeatures|PCRF_StoreLoadBypass|PCRF_DisableFPU,d0
  2824.     dc.w    $4E7B,$0808    movec    d0,pcr
  2825. .no060
  2826.     move.l    (sp)+,d0
  2827.     rts
  2828.  
  2829.  
  2830. ; IN: a1=libname, d0=version, a6=execbase
  2831. OpenLib    move.w    #_LVOOldOpenLibrary,d1
  2832.     cmp.w    #33,(LIB_VERSION,a6)
  2833.     blo.b    .oldol
  2834.     move.w    #_LVOOpenLibrary,d1
  2835. .oldol    jsr    0(a6,d1.w)
  2836.     tst.l    d0
  2837.     rts
  2838.  
  2839.  
  2840. ;  IN: a0=filename (d6=dosbase, _Printf)
  2841. ; OUT: a1=buffer, d0=buffer len, d1=file len
  2842.  
  2843. XPKLoad    movem.l    d2-d7/a2-a6,-(sp)
  2844.     move.l    a0,a3
  2845.     sub.l    a5,a5
  2846.     moveq    #0,d6
  2847.     moveq    #0,d7
  2848.  
  2849.     move.l    (4*4,sp),a6
  2850.     move.l    a3,d1
  2851. ;;    moveq    #ACCESS_READ,d2
  2852. ;;    call    Lock
  2853. ;;    move.l    d0,d1
  2854.     bsr    _lockread
  2855.  
  2856.     beq    .exit
  2857.     move.l    d1,-(sp)
  2858.     lea    (-(fib_SIZEOF+4),sp),sp
  2859.     move.l    sp,d2
  2860.     addq.l    #3,d2
  2861.     and.w    #-4,d2
  2862.     call    Examine
  2863.     move.l    d2,a0
  2864.     move.l    (fib_Size,a0),d3
  2865.     move.l    d0,d2
  2866.     lea    ((fib_SIZEOF+4),sp),sp
  2867.     move.l    (sp)+,d1
  2868.     call    UnLock
  2869.     tst.l    d2
  2870.     beq.b    .exit
  2871.  
  2872.     move.l    a3,d1
  2873.     move.l    #MODE_OLDFILE,d2
  2874.     call    Open
  2875.     move.l    d0,d5
  2876.     beq.b    .exit
  2877.  
  2878.     move.l    d5,d1
  2879.     subq.l    #4,sp
  2880.     move.l    sp,d2
  2881.     move.l    d3,-(sp)
  2882.     moveq    #4,d3
  2883.     call    Read
  2884.     move.l    (sp)+,d3
  2885.     move.l    (sp)+,d4
  2886.     subq.l    #4,d0
  2887.     bne.b    .exit
  2888.     move.l    d5,d1
  2889.     moveq    #0,d2
  2890.     move.l    d3,-(sp)
  2891.     moveq    #OFFSET_BEGINNING,d3
  2892.     call    Seek
  2893.     move.l    (sp)+,d3
  2894.     subq.l    #4,d0
  2895.     bne.b    .exit
  2896.     cmp.l    #'XPKF',d4
  2897.     beq.b    .tryxpk
  2898.  
  2899. .noxpk    move.l    (_ExecBase,pc),a6
  2900.     move.l    d3,d0
  2901.     moveq    #MEMF_PUBLIC,d1
  2902.     call    AllocMem
  2903.     move.l    (4*4,sp),a6
  2904.     move.l    d0,d2
  2905.     beq.b    .close
  2906.  
  2907.     move.l    d5,d1
  2908.     call    Read
  2909.     cmp.l    d0,d3
  2910.     bne.b    .free
  2911.  
  2912.     move.l    d3,d7
  2913.     move.l    d3,d6
  2914.     move.l    d2,a5
  2915.     bra.b    .close
  2916.  
  2917. .free    move.l    (_ExecBase,pc),a6
  2918.     move.l    d2,a1
  2919.     move.l    d3,d0
  2920.     call    FreeMem
  2921.     move.l    (4*4,sp),a6
  2922.  
  2923. .close    move.l    d5,d1
  2924.     call    Close
  2925.  
  2926. .exit    move.l    a5,a1
  2927.     move.l    d6,d0
  2928.     move.l    d7,d1
  2929.     movem.l    (sp)+,d2-d7/a2-a6
  2930.     rts
  2931.  
  2932.  
  2933. .tryxpk    move.l    (_ExecBase,pc),a6
  2934.     lea    (.xpkname,pc),a1
  2935.     moveq    #0,d0
  2936.     bsr    OpenLib
  2937.     beq    .noxpk
  2938.     move.l    d0,d2
  2939.  
  2940.     move.l    (4*4,sp),a6
  2941.     move.l    d5,d1
  2942.     call    Close
  2943.     exg    d2,a6
  2944.  
  2945. XPKERRSIZE    EQU    ((XPKERRMSGSIZE+1+3)&-4)
  2946.  
  2947.     lea    (-XPKERRSIZE,sp),sp
  2948.     move.l    sp,a4
  2949.     clr.l    -(sp)
  2950.     move.l    sp,d3
  2951.     clr.l    -(sp)
  2952.     move.l    sp,d4
  2953.     clr.l    -(sp)
  2954.     move.l    sp,d5
  2955.     clr.l    -(sp)
  2956.     moveq    #-1,d0
  2957.     move.l    d0,-(sp)
  2958.     pea    XPK_PassThru        Allow uncompressed file
  2959.     pea    MEMF_PUBLIC
  2960.     pea    XPK_OutMemType
  2961.     move.l    d5,-(sp)        buflen
  2962.     pea    XPK_GetOutBufLen
  2963.     move.l    d4,-(sp)        filelen
  2964.     pea    XPK_GetOutLen
  2965.     move.l    d3,-(sp)        outbuf
  2966.     pea    XPK_GetOutBuf
  2967.     move.l    a4,-(sp)        errbuf
  2968.     pea    XPK_GetError
  2969.     move.l    a3,-(sp)
  2970.     pea    XPK_InName
  2971.     move.l    sp,a0
  2972.     call    XpkUnpack
  2973.     move.l    d5,sp
  2974.  
  2975.     move.l    (sp)+,d6        d6=buflen
  2976.     move.l    (sp)+,d7        d7=filelen
  2977.     move.l    (sp)+,a5        a5=outbuf
  2978.  
  2979.     tst.l    d0
  2980.     beq.b    .allok
  2981.     ; a4=errbuf
  2982.     move.l    a4,a0
  2983. .finde    tst.b    (a0)+
  2984.     bne.b    .finde
  2985.     move.b    #10,(-1,a0)
  2986.     clr.b    (a0)
  2987.     move.l    a4,a0
  2988.     exg    d2,d6
  2989.     bsr    _Printf
  2990.     exg    d2,d6
  2991.  
  2992. .allok    lea    (XPKERRSIZE,sp),sp
  2993.  
  2994.     move.l    a6,a1
  2995.     move.l    (_ExecBase,pc),a6
  2996.     call    CloseLibrary
  2997.     bra    .exit
  2998.  
  2999.  
  3000. .xpkname    dc.b    'xpkmaster.library',0
  3001.     CNOP    0,2
  3002.  
  3003.  
  3004.  
  3005.  
  3006.  
  3007. ;  IN: a0=rom, d0=rom len
  3008. ; OUT: d0=success (number of patches done, or zero)
  3009. LastPatches    movem.l    d1-a6,-(sp)
  3010.     moveq    #0,d7
  3011.     move.l    a0,a6
  3012.     move.l    d0,d6
  3013.  
  3014. SUPERVISOR_NOREVERSE    SET    0
  3015.     IFNE    SUPERVISOR_NOREVERSE
  3016.     move.w    #2048/2-1,d0        during first 2k
  3017.     move.l    #$2D40003A,d1
  3018. .scan    addq.l    #2,a0
  3019.     cmp.l    (a0),d1
  3020.     dbeq    d0,.scan
  3021.     tst.w    d0
  3022.     bmi.b    .not0
  3023.     cmp.l    #$6608223C,(4,a0)
  3024.     bne.b    .scan
  3025.     cmp.l    #MEMF_CLEAR!MEMF_REVERSE,(8,a0)
  3026.     bne.b    .scan
  3027.     cmp.w    #$60EC,(12,a0)
  3028.     bne.b    .scan
  3029.  
  3030.     move.w    #MEMF_CLEAR>>16,(8,a0)
  3031.     addq.l    #1,d7
  3032. .not0
  3033.     ENDC
  3034.  
  3035.     move.l    (_OrigSum,pc),d5
  3036.     cmp.l    ROMSUMOFFS(a6,d6.l),d5
  3037.     bne    .not_correct_chksum
  3038.  
  3039.     cmp.l    #33<<16!180,($C,a6)
  3040.     bne.b    .not_33180
  3041.     cmp.l    #$56F2E2A6,d5        Must be original to patch!
  3042.     bne.b    .not_33180
  3043.  
  3044.     move.w    #$0020,($19C,a6)    2MB chip ram
  3045.     move.l    #$FF000001,($3000,a6)    ExecBase address mask
  3046.  
  3047.     IFGT    0
  3048.     move.l    #$20482249,d0        move.l a0,a0 / move.l a1,a1
  3049.     move.l    d0,($4D9A,a6)        expansion.library bug
  3050.     move.l    #$4EAEFF3A,($4D9A+4,a6)
  3051.     move.l    #$4A80672E,($4D9A+8,a6)
  3052.     move.l    #$24002200,($4D9A+12,a6)
  3053.     move.l    #$20434280,($4D9A+16,a6)
  3054.     move.l    #$302F0002,($4D9A+20,a6)
  3055.     move.w    d0,($4D9A+24,a6)
  3056.     ENDC
  3057.  
  3058.     move.l    #$20482249,d0        move.l a0,a0 / move.l a1,a1
  3059.     move.w    d0,($4D9A,a6)        expansion.library bug
  3060.     move.l    d0,($4D9A+2,a6)
  3061.     move.l    #$4A80672C,($4DA4,a6)
  3062.     move.l    #$24002240,($4DA4+4,a6)
  3063.     move.l    #$20437000,($4DA4+8,a6)
  3064.     move.b    #$30,($4DA4+12,a6)
  3065.  
  3066.     ; my:
  3067.     move.l    #$99CC4ED5,($1E6,a6)    no $C00000 mem, please !!
  3068. ;;    clr.b    ($56D,a6)        disable cache (instruction)
  3069.  
  3070.     addq.l    #1,d7
  3071. .not_33180
  3072.  
  3073.     cmp.l    #34<<16!5,($C,a6)
  3074.     bne.b    .not_3405
  3075.     cmp.l    #$15267DB3,d5        Must be original to patch!
  3076.     bne.b    .not_3405
  3077.  
  3078.     move.w    #$0020,($19C,a6)    2MB chip ram
  3079.     move.l    #$FF000001,($303C,a6)    ExecBase address mask
  3080.  
  3081.     addq.l    #1,d7
  3082. .not_3405
  3083.  
  3084. .not_correct_chksum
  3085.  
  3086.     move.l    d7,d0
  3087.     movem.l    (sp)+,d1-a6
  3088.     rts
  3089.  
  3090.  
  3091. ;  IN: a0=rom, d0=rom len
  3092. ; OUT: d0=success (number of patches done, or zero)
  3093. SpeedROM    movem.l    d1-a6,-(sp)
  3094.  
  3095.     moveq    #0,d7
  3096.     move.l    a0,a2
  3097.     move.l    d0,d4
  3098.     move.l    #$01000000,d2
  3099.     sub.l    d4,d2
  3100.     move.l    a2,a5
  3101.     sub.l    d2,a5            a5=difference
  3102.  
  3103.     move.l    (4,a2),a1
  3104.     add.l    a5,a1
  3105.  
  3106.     cmp.w    #$203C,(6,a1)        KS 1.x start: (34.5)
  3107.     bne.b    .nosp1
  3108.     cmp.l    #$53806EFC,(12,a1)
  3109.     bne.b    .nosp1
  3110.     move.w    #$6008,(6,a1)
  3111.     addq.l    #1,d7
  3112. .nosp1
  3113.     IFNE    HAVE_SPEEDROMCHECKSUM
  3114.     cmp.l    #$41F900F8,(4,a1)    KS 3.0 chksum:
  3115.     bne.b    .nosp2
  3116.     cmp.l    #$72FF7401,(10,a1)
  3117.     bne.b    .nosp2
  3118.     move.l    #$7AFF6010,(10,a1)
  3119.     addq.l    #1,d7
  3120. .nosp2
  3121.     cmp.l    #$41FAFF28,(4,a1)    KS 3.1 chksum:
  3122.     bne.b    .nosp3
  3123.     cmp.l    #$72FF7401,(8,a1)
  3124.     bne.b    .nosp3
  3125.     move.l    #$7AFF6010,(8,a1)
  3126.     addq.l    #1,d7
  3127. .nosp3
  3128.     ENDC
  3129.  
  3130.     ; Reconnect resident modules:
  3131.  
  3132.     moveq    #-(RT_SIZE+2),d1
  3133.     move.l    a2,a0
  3134.     add.l    d4,d1
  3135.     sub.l    a1,a1
  3136. .find    subq.l    #2,d1
  3137.     bls.b    .done
  3138.     cmp.w    #RTC_MATCHWORD,(a0)+
  3139.     bne.b    .find
  3140.     moveq    #2,d0
  3141.     add.l    (a0),d0            (RT_MATCHTAG-2,a0),d0
  3142.     add.l    a5,d0
  3143.     cmp.l    a0,d0
  3144.     bne.b    .find
  3145.     subq.l    #2,a0
  3146.     move.l    a1,d0
  3147.     beq.b    .is_1st
  3148.     move.l    a0,d0
  3149.     sub.l    a5,d0
  3150.     move.l    d0,(RT_ENDSKIP,a1)
  3151. .is_1st    move.l    a0,a1
  3152.     lea    (RT_SIZE,a0),a0
  3153.     bra.b    .find
  3154. .done
  3155.     move.l    a1,d0
  3156.     beq.b    .none
  3157.     ; make last RT_ENDSKIP point $00FFFFFA
  3158.     move.l    #$00FFFFFA,(RT_ENDSKIP,a1)
  3159. .none
  3160.  
  3161.     ; can't really reconnect EXTRES buffer restags
  3162.     ; ...
  3163.  
  3164.     addq.l    #1,d7
  3165.  
  3166.     move.l    d7,d0
  3167.     movem.l    (sp)+,d1-a6
  3168.     rts
  3169.  
  3170.  
  3171.     IFGT    0
  3172.  
  3173. ; *** WARNING: REQUIRES SOURCE AND DESTINATION ADDRESSES ALIGNEG BY 16! ***
  3174.  
  3175. ;  IN: a0=source ptr
  3176. ;      a1=dest ptr
  3177. ;      d0=copy len, aligned by 256
  3178. ; OUT: a0=source ptr + copy len
  3179. ;      a1=dest ptr + copy len
  3180. ;      d0=copy len
  3181. copymem256_040    move.l    d0,-(sp)
  3182.     lsr.l    #8,d0            /256
  3183. .copy    move16    (a0)+,(a1)+        16
  3184.     move16    (a0)+,(a1)+        16
  3185.     move16    (a0)+,(a1)+        16
  3186.     move16    (a0)+,(a1)+        16
  3187.  
  3188.     move16    (a0)+,(a1)+        16
  3189.     move16    (a0)+,(a1)+        16
  3190.     move16    (a0)+,(a1)+        16
  3191.     move16    (a0)+,(a1)+        16
  3192.  
  3193.     move16    (a0)+,(a1)+        16
  3194.     move16    (a0)+,(a1)+        16
  3195.     move16    (a0)+,(a1)+        16
  3196.     move16    (a0)+,(a1)+        16
  3197.  
  3198.     subq.l    #1,d0
  3199.     move16    (a0)+,(a1)+        16
  3200.     move16    (a0)+,(a1)+        16
  3201.     move16    (a0)+,(a1)+        16
  3202.     move16    (a0)+,(a1)+        16
  3203.     bne.b    .copy
  3204.     move.l    (sp)+,d0
  3205.     rts
  3206.  
  3207.     ENDC
  3208.  
  3209.  
  3210. ;  IN: a0=source ptr
  3211. ;      a1=dest ptr
  3212. ;      d0=copy len, aligned by 256
  3213. ; OUT: a0=source ptr + copy len
  3214. ;      a1=dest ptr + copy len
  3215. ;      d0=copy len
  3216. copymem256    movem.l    d0-d7/a2-a6,-(sp)
  3217.     lsr.l    #8,d0            /256
  3218. .copy    movem.l    (a0)+,d1-d7/a2-a6
  3219.     movem.l    d1-d7/a2-a6,(a1)    12*4=48
  3220.     movem.l    (a0)+,d1-d7/a2-a6
  3221.     movem.l    d1-d7/a2-a6,(1*48,a1)    12*4=48
  3222.     movem.l    (a0)+,d1-d7/a2-a6
  3223.     movem.l    d1-d7/a2-a6,(2*48,a1)    12*4=48
  3224.     movem.l    (a0)+,d1-d7/a2-a6
  3225.     movem.l    d1-d7/a2-a6,(3*48,a1)    12*4=48
  3226.     movem.l    (a0)+,d1-d7/a2-a6
  3227.     movem.l    d1-d7/a2-a6,(4*48,a1)    12*4=48
  3228.     movem.l    (a0)+,d1-d4
  3229.     movem.l    d1-d4,(5*48,a1)        4*4=16
  3230.     subq.l    #1,d0
  3231.     lea    (256,a1),a1
  3232.     bne.b    .copy
  3233.     movem.l    (sp)+,d0-d7/a2-a6
  3234.     rts
  3235.  
  3236.     ;IFGT    (copymem256_000-copymem256)-$7E
  3237.     ;FAIL    "copymem256 offset out of bra.b!"
  3238.     ;ENDC
  3239.  
  3240.  
  3241.  
  3242.  
  3243. ;  IN: a4=rom buffer
  3244. ;      d3=rom size
  3245. KickSys    movem.l    d1-a6,-(sp)
  3246.     ;illegal
  3247.  
  3248.     lea    (default_pre,pc),a2
  3249.     lea    (default_post,pc),a3
  3250.  
  3251.     move.b    (_B20x0,pc),d0
  3252.     beq.b    .not_b20x0
  3253.     lea    (b20x0_pre,pc),a2
  3254.     lea    (b20x0_post,pc),a3
  3255. .not_b20x0
  3256.  
  3257.     move.b    (_MK2,pc),d0
  3258.     beq.b    .not_csmk2
  3259.     ; uses default_pre
  3260.     lea    (csmk2_post,pc),a3
  3261. .not_csmk2
  3262.  
  3263.     move.b    (_CSPPC_MK3,pc),d0
  3264.     beq.b    .not_scppc_mk3
  3265.     lea    (csppcmk3_pre,pc),a2
  3266.     lea    (csppcmk3_post,pc),a3
  3267. .not_scppc_mk3
  3268.  
  3269.     move.b    (_BlizPPC,pc),d0
  3270.     beq.b    .not_blizzppc
  3271.     lea    (blizzppc_pre,pc),a2
  3272.     lea    (blizzppc_post,pc),a3
  3273. .not_blizzppc
  3274.  
  3275.     move.b    (_CPUCard,pc),d0
  3276.     beq.b    .notcpucard
  3277.     lea    (cpucard_pre,pc),a2
  3278.     lea    (cpucard_post,pc),a3
  3279. .notcpucard
  3280.  
  3281.  
  3282.     move.l    (_ExecBase,pc),a6
  3283.     lea    (GfxName,pc),a1
  3284.     moveq    #0,d0
  3285.     bsr    OpenLib
  3286.     tst.l    d0
  3287.     beq.b    .nogfx
  3288.  
  3289.     move.l    d0,-(sp)
  3290.     move.l    d0,a6
  3291.     call    OwnBlitter
  3292.     call    WaitBlit
  3293.     sub.l    a1,a1
  3294.     move.l    (gb_ActiView,a6),-(sp)
  3295.     call    LoadView
  3296.     call    WaitTOF
  3297.  
  3298.     ; Reset AGA hardware
  3299.     cmp.w    #39,(LIB_VERSION,a6)
  3300.     blo.b    .noaga
  3301.     btst    #GFXB_AA_ALICE,(gb_ChipRevBits0,a6)
  3302.     beq.b    .noaga
  3303.     lea    $DFF106,a0
  3304.     move.w    #$0C00,(a0)
  3305.     move.w    #$0000,($1FC-$106,a0)
  3306. .noaga
  3307.     call    WaitTOF
  3308.  
  3309.  
  3310.     ; Call the hw banging routine
  3311.  
  3312.     move.l    (_ExecBase,pc),a6
  3313.     lea    (.super,pc),a0
  3314.     bsr    runnommu
  3315.     ; We drop in here if something goes terribly wrong.
  3316.  
  3317.     ; Restore view
  3318.     move.l    (sp)+,a1
  3319.     move.l    (sp)+,a6
  3320.     call    LoadView
  3321.     call    WaitTOF
  3322.     call    DisownBlitter
  3323.  
  3324.     ; Close gfxbase
  3325.     move.l    a6,a1
  3326.     move.l    (_ExecBase,pc),a6
  3327.     call    CloseLibrary
  3328.  
  3329.     ; Whine to user
  3330.     lea    (KickSysErr,pc),a0
  3331.     bsr    _Printf
  3332.  
  3333. .nogfx    movem.l    (sp)+,d1-a6
  3334.     rts
  3335.  
  3336.  
  3337.  
  3338. .super    ori.w    #$700,sr        Disable all ints!
  3339.     bsr    CacheClrS        flush caches
  3340.  
  3341.  
  3342.     ; Do whatever init the card needs
  3343.  
  3344.     movem.l    d3/a4,-(sp)
  3345.     jsr    (a2)
  3346.     movem.l    (sp)+,d3/a4
  3347.     tst.l    d0            Did it fail?
  3348.     bne.b    .cont
  3349.     ; NOTE: MUST USE RTS HERE!
  3350.     rts
  3351.  
  3352. .cont
  3353.     ; Copy the ROM to the magic address
  3354.  
  3355.     move.l    (_BlizROM,pc),a1
  3356.  
  3357.     cmp.l    #$40000,d3        Is it 256K ROM?
  3358.     bne.b    .no1st
  3359.  
  3360.     move.l    d3,d0            Copy 256k:
  3361.     move.l    a4,a0
  3362.     bsr    copymem256
  3363. .no1st
  3364.     move.l    d3,d0            Copy ROM:
  3365.     move.l    a4,a0
  3366.     bsr    copymem256
  3367.  
  3368.  
  3369.     ; Flush & Disable caches
  3370.     ;
  3371.     bsr    DisableCacheS        Disable all caches.
  3372.  
  3373.  
  3374.     ; Do whatever post processing the card needs
  3375.     ;
  3376.     jsr    (a3)
  3377.  
  3378.  
  3379.     ; Trash execbase pointer (MMU disabled)
  3380.     ;
  3381.     bsr    trashexecbase_sv
  3382.  
  3383.  
  3384.     ; Reboot the system
  3385.     ;
  3386.     lea    $DFF09A,a0
  3387.     move.w    #$4000,(a0)+        All interrupts off
  3388.     move.w    #$3FFF,(a0)        All DMA off
  3389.  
  3390.     lea    $01000000+4,a0        ...and reboot...
  3391.     sub.l    (ROMSIZEOFFS-4,a0),a0
  3392.     move.l    (a0),a0
  3393.     subq.l    #2,a0
  3394.     IFGT    (*-Main)&2        Main must be longword aligned!
  3395.     move.l    a1,a1
  3396.     ENDC
  3397.     reset
  3398.     jmp    (a0)
  3399.  
  3400.  
  3401.  
  3402. ; Trash execbase pointer, in both supervisor and user state
  3403. ;
  3404. ;  IN: - (supervisor state, interrupts disabled)
  3405. ; OUT: d0-d1/a0-a1 trashed
  3406. trashexecbase_sv
  3407.     move.l    (_Array+ARG_KEEPEXEC,pc),d0
  3408.     bne.b    .exit
  3409.  
  3410.     sub.l    a1,a1
  3411.     btst    #AFB_68010,(_AttnFlags+1,pc)
  3412.     beq.b    .novbr
  3413.     movec    vbr,a1
  3414. .novbr
  3415.     lea    (8*4,a1),a1        ; vector 8 (privilege violation)
  3416.     lea    (.privilege_violation,pc),a0
  3417.     move.l    (a1),d1            ; save old privilege violation vector
  3418.     move.l    a0,(a1)            ; set new privilege violation vector
  3419.  
  3420.     lea    (4).w,a0
  3421.     moveq    #-1,d0
  3422.     move.l    d0,(a0)            ; Trash execbase (supervisor)
  3423.  
  3424.     move.l    d0,(4-(8*4),a1)        ; Trash execbase (in VBR table)
  3425.  
  3426.     and.w    #~$2000,sr        ; drop to user state
  3427.                     ; (must not use (sp) here, USP could be inaccessable!)
  3428.     move.l    d0,(a0)            ; Trash execbase (user)
  3429.  
  3430.     ori.w    #$2000,sr        ; back to supervisor
  3431.     nop
  3432.  
  3433.     move.l    d1,(a1)            ; restore privilege violation vector
  3434.  
  3435.     bsr    CacheClrS
  3436. .exit    rts
  3437.  
  3438. .privilege_violation
  3439.     or.w    #$2000,(sp)        ; force supervisor
  3440.     nop
  3441.     rte                ; and re-try
  3442.  
  3443.  
  3444.  
  3445.     ; Default: Blizzard 12x0
  3446. default_pre
  3447.     moveq    #1,d0
  3448. default_post
  3449.     rts
  3450.  
  3451.  
  3452.     ; Blizzard 2040-ERC / 2060
  3453. b20x0_pre
  3454.     move.l    (_BlizROM,pc),a0
  3455.  
  3456.     moveq    #4-1,d0
  3457. .loop    moveq    #0,d1            Turn shadow off
  3458.     bsr.b    SetMemShadow
  3459.  
  3460.     move.l    (4,a0),-(sp)        Do some poking magic
  3461.     move.l    (a0),-(sp)
  3462.     move.l    (sp),d2
  3463.     move.l    d2,d1
  3464.     eor.l    #$BADC0DE5,d2
  3465.     move.l    d2,(a0)            Write test long
  3466.     nop
  3467.     move.l    d1,(4,a0)        Trash bus
  3468.     nop
  3469.     move.l    (a0),d1            Read test long
  3470.     nop
  3471.     move.l    (sp)+,(a0)        Restore to original
  3472.     move.l    (sp)+,(4,a0)
  3473.     nop
  3474.     bsr    CacheClrS
  3475.  
  3476.     cmp.l    d2,d1            Found mapping?
  3477.     beq.b    .found
  3478.  
  3479.     moveq    #1,d1            Turn shadow on
  3480.     bsr.b    SetMemShadow
  3481.  
  3482.     subq.l    #1,d0
  3483.     bpl.b    .loop
  3484.  
  3485.     ; return failure
  3486.     moveq    #0,d0
  3487.  
  3488. .exit    bra    CacheClrS
  3489.  
  3490.  
  3491. .found
  3492.     lea    (_B20x0Bank,pc),a0
  3493.     move.l    d0,(a0)
  3494.  
  3495.     ; return success
  3496.     ; NOTE: The shadow is *left* off intentionally!
  3497.  
  3498.     moveq    #1,d0
  3499.     bra.b    .exit
  3500.  
  3501.  
  3502. b20x0_post
  3503.     moveq    #1,d1            Turn shadow on
  3504.     ; [FALL THRU]
  3505. ;
  3506. ; This one is from old CyberMap I think...
  3507. ; Modified a bit.
  3508. ;
  3509. ;*********************************************************
  3510. ;*       writes memshadowregister of the given rambank
  3511. ;*       setmemshadow(D0=bank,D1=on/off (bool))
  3512. ;*********************************************************
  3513. ;*       $ 8    2    c
  3514. ;*       %100x yy10 1100 ---- ---- ---- ---- ----Shadow Register Format
  3515. ;*                    x = Set/Clr Flag  0=on 1=off
  3516. ;*                    y = Bank Number
  3517. MEMSHWREG    EQU    $82C00000        Shadow Enable Control Register
  3518.  
  3519. SetMemShadowN    move.l    (_B20x0Bank,pc),d0
  3520.     ; [FALL THRU]
  3521.  
  3522. ; IN: d0=bank, d1=mode
  3523. SetMemShadow    movem.l    d0-d1/a6,-(sp)
  3524.  
  3525.     ror.l    #6,d0            shift in place
  3526.     or.l    #MEMSHWREG,d0        mask in MEMSHWREG adr
  3527.     tst.l    (4,sp)            d1 from stack
  3528.     bne.b    .sf_skip        =! 0 -> TRUE -> b28=0
  3529.     bset    #28,d0            == 0 -> FALSE -> b28=1
  3530. .sf_skip    move.l    d0,a6            Write Register
  3531.  
  3532.     moveq    #%011,d0
  3533.     movec    dfc,d1            store old DFC
  3534.     movec    d0,dfc            set DFC to %011
  3535.     nop
  3536.     moves.l    a6,(a6)
  3537.     nop
  3538.     movec    d1,dfc            restore old DFC
  3539.     movem.l    (sp)+,d0-d1/a6
  3540.     rts
  3541.  
  3542.  
  3543.  
  3544.  
  3545.  
  3546.     ; Cyberstorm MK II
  3547. csmk2_post
  3548.     bset    #7,$00DE0002        Set Gary Coldstart
  3549.  
  3550.     move.b    #$2A,$880000E3        Trigger MKII maprom
  3551.     nop
  3552.     rts
  3553.  
  3554.  
  3555.  
  3556.     ; Cyberstorm MK III or PPC
  3557.  
  3558. csppcmk3_pre
  3559.     bset    #7,$00DE0002        Set Gary Coldstart
  3560.  
  3561.     lea    (csppc_mkiii_code1,pc),a0
  3562.     bsr    runwithmmu040
  3563.     moveq    #1,d0
  3564.     rts
  3565. csppcmk3_post
  3566.     lea    (csppc_mkiii_code2,pc),a0
  3567.     bra.b    csppcmk3_comm
  3568.  
  3569.  
  3570.  
  3571.  
  3572.     ; BlizzardPPC
  3573. blizzppc_pre
  3574.     lea    (blizppc_code1,pc),a0
  3575.     bsr    runwithmmu040
  3576.     moveq    #1,d0
  3577.     rts
  3578. blizzppc_post
  3579.     lea    (blizppc_code2,pc),a0
  3580. csppcmk3_comm    bsr    runwithmmu040
  3581.     ;;bra.b    pupcard_reboot
  3582.  
  3583. pupcard_reboot
  3584.     ; Some PowerUP cards somehow screw up when rebooted
  3585.     ; with the magic below. If NOPUPREBOOT option is set
  3586.     ; this code is not run, but regular reboot code is
  3587.     ; executed instead.
  3588.     ;
  3589.     ; This *finally* fix the annoying red screen crashes
  3590.     ; with these systems, I hope.
  3591.     ;
  3592.     move.l    (_Array+ARG_NOPUPREBOOT,pc),d0
  3593.     bne.b    .nopupreboot
  3594.  
  3595.     ; Trash execbase pointer (MMU disabled)
  3596.     ;
  3597.     bsr    trashexecbase_sv
  3598.  
  3599.     ; trigger the card to reboot the system
  3600.     ;
  3601.     move.b    #$40,$00F60018        ; blizzppc/csppc/mkiii
  3602.     move.b    #$0C,$00F60000        ; majik
  3603.     nop
  3604.     nop
  3605.     ;
  3606.     ; NOTE: We should never get here, the code above trigger
  3607.     ; hard reset.
  3608.     ;
  3609.     rts
  3610.  
  3611. .nopupreboot
  3612.     move.b    #$40,$00F60018        ; blizzppc/csppc/mkiii majic
  3613.     rts
  3614.  
  3615.  
  3616.  
  3617.     ; Cyberstorm MK I / A3640 / Blizzard A4030
  3618. cpucard_pre
  3619.     bset    #7,$00DE0002        Set Gary Coldstart
  3620.  
  3621.     clr.b    $00DE0000        Gary bootflags=ColdStart
  3622.     clr.b    $00DE0001
  3623.     nop
  3624.     move.l    #1,$80F80000        Trigger maprom
  3625.     nop
  3626.  
  3627.     moveq    #1,d0
  3628.     rts
  3629.  
  3630. cpucard_post
  3631.     move.b    #$80,$00DE0000        Gary BootFlag=ColdBoot
  3632.     move.b    #$80,$00DE0001
  3633.     rts
  3634.  
  3635.  
  3636.  
  3637.     ; Some BlizzardPPC / CS PPC / CS MK III routines
  3638.  
  3639. blizppc_code1
  3640.     clr.b    $00F60013        Turn off BlizPPC maprom
  3641.  
  3642.     ; fall thru
  3643.  
  3644. csppc_mkiii_code1
  3645.     nop
  3646.     nop
  3647.     move.b    #$10,$00F60000        blizzppc/csppc/mkiii
  3648.     nop                majik
  3649.     nop
  3650.     rts
  3651.  
  3652. csppc_mkiii_code2
  3653.     lea    $00F60020,a0        Trigger PPC/MKIII maprom
  3654.     move.b    #$60,(a0)
  3655.     nop
  3656.     move.b    #$50,(a0)
  3657.     nop
  3658.     move.b    #$30,(a0)
  3659.     nop
  3660.     move.b    #1,(-8,a0)
  3661.     nop
  3662.     clr.b    (a0)
  3663.     nop
  3664.  
  3665.     ; fall thru
  3666.  
  3667. pupcard_common
  3668.     ; disable interupts
  3669.  
  3670.     lea    $DFF09A,a0
  3671.     move.w    #$4000,(a0)+        All interrupts off
  3672.     move.w    #$3FFF,(a0)        All DMA off
  3673.  
  3674.     nop
  3675.     nop
  3676.     nop
  3677.     nop
  3678.  
  3679.     ; If no Enforcer/CyberGuard/MuForce is running,
  3680.     ; trash execbase with original MMU tables too.
  3681.     ; Strictly speaking, this is not needed, but
  3682.     ; this doesn't hurt either.
  3683.     ;
  3684.     move.l    (_EnforcerFlag,pc),d0
  3685.     bne.b    .dontpoke
  3686.  
  3687.     ; Trash execbase pointer (MMU enabled)
  3688.     ;
  3689.     bsr    trashexecbase_sv
  3690. .dontpoke
  3691.     rts
  3692.  
  3693.  
  3694. blizppc_code2
  3695.     clr.b    $00F60012        Trigger BlizPPC maprom
  3696.     nop
  3697.  
  3698.     bra.b    pupcard_common
  3699.  
  3700.  
  3701. TestCPUCard
  3702.     movem.l    d1-d7/a0-a6,-(sp)
  3703.     moveq    #0,d7
  3704.     move.l    (_ExecBase,pc),a6
  3705.     call    Forbid
  3706.  
  3707.     lea    (MemList,a6),a5
  3708.     lea    (LH_TAIL,a5),a4
  3709.  
  3710.     move.l    #$07000000,d1
  3711.     move.l    #$08000000,d2
  3712. .loop    move.l    (a5),a5
  3713.     cmp.l    a5,a4
  3714.     beq    .nomem
  3715.     moveq    #MEMF_POOLMEM!MEMF_CHIP!MEMF_FAST!MEMF_PUBLIC,d0    Public fast?
  3716.     and.w    (MH_ATTRIBUTES,a5),d0
  3717.     cmp.w    #MEMF_FAST!MEMF_PUBLIC,d0
  3718.     bne.b    .loop
  3719.     cmp.l    (MH_LOWER,a5),d1
  3720.     bhi.b    .loop
  3721.     cmp.l    (MH_UPPER,a5),d2
  3722.     blo.b    .loop
  3723.  
  3724.     bsr    FoundMem
  3725.  
  3726.     call    Permit
  3727.  
  3728.     IFNE    HAVE_CPUCARDPOKING
  3729.     bsr.b    CheckCPUCard
  3730.     tst.l    d0
  3731.     beq.b    .exit
  3732.     ENDC
  3733.  
  3734.     ; exit ok
  3735.     lea    (_BlizROM,pc),a0
  3736.     move.l    #$07F80000,(a0)
  3737.  
  3738.     moveq    #1,d0
  3739. .exit
  3740.     movem.l    (sp)+,d1-d7/a0-a6
  3741.     rts
  3742.  
  3743.  
  3744. .nomem    call    Permit
  3745.     moveq    #0,d0
  3746.     bra.b    .exit
  3747.  
  3748.  
  3749.     IFNE    HAVE_CPUCARDPOKING
  3750.  
  3751. ;  IN: -
  3752. ; OUT: d0,cc=nonzero if CPU Card with MAPROM present, else zero
  3753. CheckCPUCard    movem.l    d7/a6,-(sp)
  3754.     moveq    #0,d7
  3755.     move.l    (_ExecBase,pc),a6
  3756.     cmp.w    #37,(LIB_VERSION,a6)
  3757.     blo.b    .exit
  3758.     call    Forbid
  3759.  
  3760.     bsr.b    cachecontroli
  3761.     move.l    d0,-(sp)
  3762.  
  3763.     lea    (.nommu,pc),a0
  3764.     bsr    runnommu
  3765.     move.l    d0,d7
  3766.  
  3767.     move.l    (sp)+,d0
  3768.     bsr.b    cachecontrol
  3769.  
  3770.     call    Permit
  3771. .exit    move.l    d7,d0
  3772.     movem.l    (sp)+,d7/a6
  3773.     rts
  3774.  
  3775. .nommu    ori.w    #$700,sr        Lock All Irqs
  3776.     moveq    #0,d2
  3777.     clr.b    $DE0000            Gary bootflags=ColdStart
  3778.     clr.b    $DE0001
  3779.     nop
  3780.     move.l    #1,$80F80000        Trigger maprom
  3781.     nop
  3782.     move.l    $07F80000,d0        Test MAPROM
  3783.     cmp.l    $00F80000,d0
  3784.     bne.b    .nomap
  3785.     move.l    d0,d1            2nd test
  3786.     not.l    d1
  3787.     move.l    d1,$07F80000
  3788.     cmp.l    $F80000,d1
  3789.     beq.b    .does_map
  3790. .xit    move.l    d0,$07F80000
  3791. .nomap    move.b    #$80,$DE0000        Gary bootflags=Warmstart
  3792.     move.l    d2,d0
  3793.     rts
  3794.  
  3795. .does_map    moveq    #1,d2
  3796.     bra.b    .xit
  3797.  
  3798.  
  3799. cachecontroli    moveq    #CACRF_EnableI!CACRF_IBE,d0
  3800. cachecontrol    move.l    #~CACRF_WriteAllocate,d1
  3801.     jmp    (_LVOCacheControl,a6)
  3802.  
  3803.     ENDC
  3804.  
  3805.  
  3806. DosName    dc.b    'dos.library',0
  3807. _mmuflag    EQU    *-1
  3808. GfxName    dc.b    'graphics.library',0
  3809.     dc.b    '$VER: '
  3810. _Version    dc.b    'BlizKick 1.24 (26.10.01)',0
  3811.     dc.b    '$COPYRIGHT: '
  3812. _Copyright    dc.b    'Copyright © 1996-2001 PitPlane Productions',0
  3813. _Template    dc.b    'KICKFILE,MODULE/M,EXTRESBUF/N,SANITY/K/N,FORCE/S,'
  3814.     dc.b    'SPEEDROM/S,HOGWAITBLIT/S,CPUCARD=CSMKI/S,'
  3815.     dc.b    'IGNPATH=IGNOREBKMODPATH/S,NOPUPREBOOT/S,KEEPEXEC/S,'
  3816.     dc.b    'QUIET/S',0
  3817. _13Help    dc.b    'Usage: BlizKick ',$9b,'1mKICKFILE',$9b,'0m',10
  3818.     dc.b    'KICKFILE is full path for the ROM image to kick.',10,0
  3819. _ks13error    dc.b    'DOS Error #%ld!',10,0
  3820.     IFD    HAVE_NEW_ENV_METHOD
  3821. _VarEnvArcName    dc.b    'ENVARC:'
  3822. _VarName    dc.b    'BKMODPATH',0
  3823.     IFNE    HAVE_DEFBKMODPATH
  3824. _DefaultBKMODPATH
  3825.     dc.b    'DEVS:Modules/',0
  3826.     ENDC
  3827.     ELSE
  3828. _EnvName    dc.b    'ENVx',0
  3829. _EnvArcName    dc.b    'ENVARC:',0
  3830. _VarName    dc.b    'BKMODPATH',0
  3831.     ENDC
  3832.  
  3833. _enforcer    dc.b    '_The Enforcer_',0
  3834.  
  3835. NoHardware    dc.b    'BlizKick requires turbo board/CPU-card with MAPROM feature.',10,0
  3836. NoCPUCard    dc.b    'Couldn''t find CPU Card (or motherboard memory)!',10,0
  3837. PlantError    dc.b    'Couldn''t plant module ''%s''!',10,0
  3838. Messu    dc.b    'Phase5 turbo board MapROM tool written by Harry "Piru" Sintonen.',10,0
  3839. Messu2    dc.b    'Kicking AMIGA ROM Operating System %d.%d.',10,0
  3840. Already    dc.b    'Kickstart is already kicked!',10,0
  3841. CouldNotKick    dc.b    'Couldn''t kick file ''%s''!',10,0
  3842. NoRem    dc.b    'Kickstart wasn''t kicked using BlizKick!',10,0
  3843. NoRestore    dc.b    'Kickstart restoring not supported!',10,0
  3844. KickSysErr    dc.b    'Hardware banging failed!',10,0
  3845.  
  3846.     CNOP    0,4
  3847. _ExecBase    ds.l    1
  3848. _EnforcerFlag    ds.l    1
  3849. _mmubase    ds.l    1
  3850. _Array    ds.l    12
  3851. _BlizROM    ds.l    1
  3852. _Quiet    ds.l    1
  3853. _OrigSum    ds.l    1
  3854. _erh_alloclen    ds.l    1
  3855. _erh_freeaddr    ds.l    1
  3856. _erh_arealen    ds.l    1
  3857. _erh_areastart    ds.l    1
  3858. _B20x0Bank    ds.l    1
  3859. _mmuregs
  3860. _itt0    ds.l    1        }
  3861. _itt1    ds.l    1        }
  3862. _dtt0    ds.l    1        } fixed order
  3863. _dtt1    ds.l    1        }
  3864. _cacr    ds.l    1        }
  3865. _tc    ds.l    1        }
  3866. _memhead    ds.b    MH_FIRST
  3867. _AttnFlags    ds.w    1
  3868. _MemHeaderFlag    ds.b    1
  3869. _B20x0    ds.b    1
  3870. _CPUCard    ds.b    1
  3871. _CSPPC_MK3    ds.b    1
  3872. _MK2    ds.b    1
  3873. _BlizPPC    ds.b    1
  3874.  
  3875. COPYCODE_SIZEOF    EQU    (*-Copy+7)&-8
  3876.  
  3877.     END
  3878.  
  3879.  
  3880. ; maprom not on:
  3881. ;
  3882. ; CS MKI     MH_UPPER & $80000 == 0
  3883. ; CS MKII    MH_UPPER & $80000 == 0
  3884. ; CS MKIII   MH_UPPER & $80000 == 0
  3885. ; CS PPC     MH_UPPER & $80000 != 0
  3886. ; BLIZZ PPC  MH_UPPER & $F0000 != 0
  3887. ;
  3888.  
  3889.  
  3890. ; model     id       mem     start     end        notes  maprom
  3891. ;turbo mem 2140/?    -        ?       - ?          A500
  3892. ; 1220     2140/0C   4 meg   $00200000-$00600000  A1200
  3893. ; 1230-I   2140/0?   ? meg   $????????-$????????  A1200  $????????
  3894. ; 1230-II  2140/0B   4 meg   $0E000000-$0E400000  A1200  $0FF80000 ! ??
  3895. ; 1230-II  2140/0B   8 meg   $????????-$????????  A1200  $1EF80000 ! ??
  3896. ; 1230-III 2140/0D   8 meg   $1DC00000-$1E400000  A1200  $1EF80000
  3897. ; 1230-III 2140/0D  32 meg   $1D000000-$1EF80000  A1200  $1EF80000
  3898. ; 1230-IV  2140/11   8 meg   $78000000-$78800000  A1200  $4FF80000
  3899. ; 1230-IV  2140/11   2 meg   $78000000-$78200000  A1200  $4FF80000?
  3900. ; 1230-IV  2140/11  16 meg   $68000000-$68F80000  A1200  $4FF80000?
  3901. ;?1260     2140/11   4 meg   $68000000-$68400000  A1200  $4FF80000 040&060 flag set!
  3902. ;>1260     2140/11   8 meg   $78000000-$78800000  A1200  $4FF80000 040&060 flag set!
  3903. ;?1260     2140/11  16 meg   $68000000-$69000000  A1200  $4FF80000 040&060 flag set!
  3904. ; 1260     2140/11   4 meg   $68000000-$68380000  A1200  $4FF80000? 040&060 flag set!
  3905. ; 1240-T   2140/11  16 meg   $68000000-$69000000  A1200  $4FF80000? 040 flag set!
  3906. ; 2040-ERC 2140/18   8 meg   $08000000-$08800000  A2000  $???????? 040 flag set!  'blizzard fastram'
  3907. ; 2060     2140/18  20 meg   $08000000-$09400000  A2000  $???????? 040&060 flag set!
  3908. ; 4030     2140/?    -        ?       - ?         A4000
  3909.  
  3910. ; CSMKI    2140/0C  32 meg   $08000000-$0A000000  A4000  csmagic  040 flag set
  3911. ; CSMKII   2140/19  80 meg   $08000000-$0D000000  A4000  csmagic
  3912. ; CS-PPC   2140/64   ? meg    ?       - ?         A4000 
  3913. ; BLIZPPC  2140/6E  16 meg   $68000000-$68800000  A1200  $FFF00000 040 flag set
  3914.  
  3915.  Board (unidentified):   Prod=8512/25($2140/$19) (@$EA0000 128K)
  3916.  Board (unidentified):   Prod=2092/18($82C/$12) (@$E90000 64K)
  3917.  Board (unidentified):   Prod=2167/201($877/$C9) (@$EC0000 64K)
  3918.  Board (unidentified):   Prod=8512/34($2140/$22) (@$40000000, size 64meg, subsize same)
  3919.  
  3920. last one is CV 64
  3921.  
  3922.  VERS:   Kickstart version 40.70, Exec version 40.10, Disk version 40.42
  3923.  RAM:    Node type $A, Attributes $505 (FAST), at $8000000-$CFFFFFF (80.0 meg)
  3924.  
  3925.  
  3926. *** CS MK I:
  3927.  
  3928. PROCESSOR:    CPU 68040/68882fpu
  3929. CUSTOM CHIPS:    AA PAL Alice (id=$0023), AA Lisa (id=$00F8)
  3930. VERS:    Kickstart version 39.106, Exec version 39.47, Disk version 39.29
  3931. RAM:    Node type $A, Attributes $505 (FAST), at $8000000-$9FFFFFF (32.0 meg)
  3932.     Node type $A, Attributes $703 (CHIP), at $2000-$1FFFFF (~2.0 meg)
  3933. BOARDS:
  3934. =======================================================================
  3935.  Board + ROM (HD?) (unidentified):   Prod=8512/12($2140/$C) (@$E90000 64K)
  3936.  ConfigDev structure found at location $2840
  3937. ==== Board ID (ExpansionRom) information:
  3938. er_Manufacturer         =8512=$2140=(~$DEBF)
  3939. er_Product              =12=$C=(~$F3)
  3940. er_Type                 =$D1
  3941.   (type 3, size 64K, not for free list, ROM diag vec valid, not chained)
  3942. er_Flags                =$0
  3943.   (no space preference, can be shut up)
  3944. er_InitDiagVec          =$80
  3945. DiagCopy at             =$8003320
  3946. ==== Configuration (ConfigDev) information:
  3947. cd_BoardAddr            =$E90000
  3948. cd_BoardSize            =$10000 (64K)
  3949. cd_Flags                =$0  (CONFIGME bit cleared)
  3950.